0

I would like to add a button to a list that I am generating using JSOM on a SharePoint page. I want this button to trigger a link in a pop-up window that changes based on the ID of each item in the list. I know how to do this getting the ID of the current page but I have run into problems with getting it to work with JSOM. Here is the relevant part of the code. I am pretty sure part of the problem is that there are too many quotation marks.

Edit I have fixed the quotation marks but the code still isn't working. When I debug it looks like dialogfunction is not being called. dialog function is in a seperate js file that I load with the page.

Edit 2 Changing the double quotes to single quotes after the backslashes fixed the problem, now it works!

var oListItem = listEnumerator.get_current();
listItemInfo += '<button onclick="dialogfunction(\'/sites/CustomSite/Doc%20Repository/Forms/EditForm.aspx?ID=""' + oListItem.get_id() + '\'); return false;">View Properties</button>' + '<strong>Name: </strong> ' + oListItem.get_item('FileLeafRef') + ' <strong>Title:</strong> ' + oListItem.get_item('Title') + ' <strong>Status:</strong> ' + oListItem.get_item('_Status') + '<br />';
    }
    $("#divListItems").html(listItemInfo);
        },
3
  • you are quite right, look at this: onclick="dialogfunction(\"/sites/CustomSite/Doc%20Repository/Forms/EditForm.aspx?ID=' + oListItem.get_id() + '\"); return false;"
    – Marco
    Aug 14, 2015 at 16:04
  • You need to escape your string. Have a look at the Special Characters section over here w3schools.com/js/js_strings.asp Aug 14, 2015 at 16:39
  • Thanks I had forgotten about putting a backslash before extra quotation marks. But it is still not working. The button appears but when I click on it the page just reloads and I get an uncaught syntax error missing } from the second line of the code on my page, which is really odd because there is no code on the second line.
    – James11
    Aug 14, 2015 at 16:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.