Reputation: 1495
Is there a way to get a current list item ID using JavaScript?
Any help is appreciated.
Upvotes: 2
Views: 8115
Reputation: 151
I found this is the easiest way
SP.ScriptHelpers.getDocumentQueryPairs()["ID"]
Upvotes: 0
Reputation: 31
Use this function: GetUrlKeyValue("ID")
<script type="text/javascript" src="/jquery-1.10.2.min.js"></script>
<script src="/jquery.SPServices-2013.02a.js" type="text/javascript"></script>
<script type="text/javascript">
var itemid = GetUrlKeyValue("ID")
</script>
Upvotes: 3
Reputation: 1495
<script type="text/javascript" src="/jquery-1.10.2.min.js"></script>
<script src="/jquery.SPServices-2013.02a.js" type="text/javascript"></script>
<script type="text/javascript">
var docurl = document.URL;
var beginindex = docurl.indexOf('?ID=') + 4;
var endindex = docurl.indexOf('&Source=');
var itemid = docurl.substring(beginindex, endindex);
</script>
Upvotes: 1