Kate
Kate

Reputation: 1495

Get selected (current) list item ID

Is there a way to get a current list item ID using JavaScript?

Any help is appreciated.

Upvotes: 2

Views: 8115

Answers (3)

Jefin Mathew
Jefin Mathew

Reputation: 151

I found this is the easiest way

SP.ScriptHelpers.getDocumentQueryPairs()["ID"]

Upvotes: 0

lili
lili

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

Kate
Kate

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

Related Questions