0

I have a page which lists visitors for an event. In case the user doesnt see the RSVP for their, I want to present a link which sends the user to the Add/New form for the visitors table... and I want to do it as a popup/dialogue.

What I have at the moment is a CEWP with the following (copied from Designer):

<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
<![CDATA
    [​Dont see the person you were looking for? 
    <a href="javascript:displayLayover(&quot;../Lists/VisitRequest_PeopleInfo/NewVisitor.aspx?EventID=@EventID&amp;IsDlg=1&quot;)">
        Add them to the visit request
    </a>
    ]
]>
</Content>

The page this code is on uses a URL parameter ("ID") to know which event the user wants to view visitors for. How can I use this URL parameter and pass it into the hyperlink? Right now the placeholder in the URL is @EventID.

It is important to get this variable working to ensure the visitor gets added to the correct event (the new visitor page uses this parameter to set the event ID).

The JavaScript function (displayLayover) I am using to get the Dialogue Box is:

<script type="text/javascript">

 function displayLayover(url) {

 var options = SP.UI.$create_DialogOptions();

 options.url = url;

 options.dialogReturnValueCallback = Function.createDelegate(

 null, null);

 SP.UI.ModalDialog.showModalDialog(options);

 }

 </script>

Thanks!!

  • You want to append the ID parameter on the current page URL to the hyperlink like this ../Lists/VisitRequest_PeopleInfo/NewVisitor.aspx?ID=1&EventId=@EventntID. Am I right? – Venkat Konjeti Aug 1 '17 at 15:19
  • Yes, but, having issues using it inside CDATA elements – njphillips01 Aug 1 '17 at 15:20
  • on the click event, you are executing a JS function there you can get the ID parameter and append to the URL. Example you can find in below answer. – Venkat Konjeti Aug 1 '17 at 15:27
0

You can update the javascript as below.

<script type="text/javascript">
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, " "));
}
function displayLayover(url) {
    var options = SP.UI.$create_DialogOptions();
    var id = getParameterByName("ID");
    options.url = url + "&ID=" + id;
    options.dialogReturnValueCallback = Function.createDelegate(null, null);
    SP.UI.ModalDialog.showModalDialog(options);
}

</script>

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.