I need to grab ID from the value user selects from a dropdown box. I had this code from years back and it worked before but now it returns everything. (see print shot of the alert). All I needed is the Item ID not item id;#value (for example, 3;#Alaska(AK)

enter image description here

NWF$(document).ready(function () {
    var obj = NWF$('#' + jsDDTitle);
    obj.change(function() {
        var clientContext = SP.ClientContext.get_current();
        var web = clientContext.get_web();
        var oList = clientContext.get_web().get_lists().getByTitle("AllStates");
        //var itemID =  (this.value).substr(0, addy.indexOf('";"')); 
        var listItem = oList.getItemById(this.value);
        clientContext.load(listItem, "LinkTitle", "Modified", "Capital");
        clientContext.executeQueryAsync(function () {        
        alert('line 3');
        document.getElementById(jsCapital).value = listItem.get_item('Capital');}, function () {        });

Just split the value and use left part, which holds your id:

var listItem = oList.getItemById(this.value.split(";#")[0]);
  • 1
    WOW. worked in first try. Normally I have to back and forth few times before someone understands the issue. You so smart and thanks for being generous with your time and help. I appreciate it – Ruby Trustit Dec 12 '18 at 14:48

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.