0

I'm a wanna be programmer with my first question here :)

I'm using SP 2010 Foundation without any option to program on server side or with SharePoint Designer. I need to add a button on a "View form" of a list (https://SITE/LIST/DispForm.aspx?ID=384)

The button's code is:

<input class="afxAddItemButton" onclick="window.location.href=&#39;https://SITE/PAGE_ADDRESS.aspx?dbSpListId=ITEM ID HERE&#39;" type="button" value="Button name"/>

I also have a JS script registered on this page. This code is used on another page to read dbSpListId value from URL, so I guess it could be modified to read ID value from "View item" page:

function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}     

Unfortunately I don't know how to place the value extracted by JS into the button code. Is it even possible?

Best regards!

1 Answer 1

0

Please see the code below:

document.querySelector('.afxAddItemButton').onclick = function redirect() {
    window.location = "https://SITE/PAGE_ADDRESS.aspx?dbSpListId=" + GetUrlKeyValue("ID")
}

If you place this code before you button you might want to wrap the code in

document.addEventListener("DOMContentLoaded", function(event) {
    ...
});
2
  • Sorry, but I will need further guidance. On the "Display Form" page I have a Content Editor Web Part, with button code mentioned before, and below is the standard view properties form. Where and in which type of Web Part should I place the code you provided? And do I need to modify the button code? I have tried multiple options, still it's not working.
    – MiTu
    Commented Sep 14, 2016 at 13:42
  • It should should suffice to wrap the code in script tags and place it after the button in your CEWP. No changes to the button required. Commented Sep 14, 2016 at 14:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.