In my SharePoint 2013 list , i am trying to get the ids of selected items using javascript . I used below script in content editor web part :

enter image description here

by using this i am able to get the ids . but i have two problems:

  1. the result i am getting is like - 1,1,0 or 1,2,0 if i select items.

  2. I need to get the collection of selected.

  3. I need to select item by clicking on checkbox which is not working although i have put up input type as checkbox id.

  • That code works? I see quite a few issues with it – wjervis Mar 1 '17 at 12:08

Please mark Sam's answer as the correct one.

Note that on the current ListView page the global ctx is already available,
so a call to get_current() is not required

SP.ListOperations take the default ctx when none is specified.

var selected=SP.ListOperation.Selection.getSelectedItems();

Gets you an Object array

var selectedStr = selected.map(function(item){ // loop all Objects
    return item.id;                            // return the ID
}).join(',');                                  // concatenate to one string 
console.log('selected IDs:',selectedStr);
| improve this answer | |

Please use below code.

function clickMethod() {

var ctx = SP.ClientContext.get_current();

var items = SP.ListOperation.Selection.getSelectedItems(ctx);

var mySeletedItems = '';

 var i;

 for (i in items)
      mySeletedItems += '|' + items[i].id;
alert (mySeletedItems);


Hope it will works for you.

| improve this answer | |

If you want to get the selected items from the list view, you can use the SP.ListOperation to get the selected items using Javascript. Refer this

Also, the below for more references. https://msdn.microsoft.com/en-us/library/office/ff407815(v=office.14).aspx


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.