Friday, March 13, 2015

Get all items selected using JavaScript in SharePoint 2013 or SharePoint Online




In this post we will discuss how to get id of all the selected items from the SharePoint list using JavaScript. The same code will work for SharePoint Online also.

Just put the below code inside a script editor web part. Then on click on the button, it will display you id of all the items you have selected.

<input type='button' id='123' value='Click Me' onclick="getSelectedItems();"/>

<script language="javascript" type="text/javascript">
function getSelectedItems()
{
var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var myItems = '';
var i;
for (i in items){
    myItems = items[i].id;
alert(myItems);
}
}
</script> 


0 comments:

Post a Comment

Twitter Delicious Facebook Digg Favorites More