Get selected item id from SharePoint 2013 list view using JSOM (JavaScript object model)

This SharePoint 2013 tutorial explains, how to get selected item id’s from a SharePoint 2013 list view by using JavaScript object model (jsom). Here I have a SharePoint 2013 list which has few items. Now in the All Items view I want to know on a button click what are items selected, basically I want to get the ids of the items.

Get selected item id from SharePoint 2013 list view using JSOM (JavaScript object model)

Here I have taken a button and on the button click, we are retrieving selected list item id from SharePoint list view using javascript.

Open your SharePoint 2013 site in the browser then open the list (All Items view). Then edit the page and click on Add a web part to add a web part. Then from the Media and Content select a Script Editor web part to the page. Then put the below code inside the script editor web part.

<input type='button' value='Get Item IDs' onclick="clickMethod();"/>

<br />
<script language="javascript" type="text/javascript">
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);
}
</script>

Now Save the page and select few items from the list and then click on the button, it will display you id’s of the selected items in a dialog box as shown in the fig below:

Get selected item id from SharePoint 2013 list view using  javascript
Get selected item id from SharePoint 2013 list view using javascript

You may like following JSOM SharePoint tutorials:

Hope this SharePoint tutorial explains, how to get selected item id from SharePoint 2013 list view using JSOM (JavaScript object model).

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

>