0

I have this code that opens a form from an image button and I want the form to open modally.

<a class="ms-addnew" id="idHomePageNewItem" href="https://thisCompany.com/HR/PerfRev/_layouts/listform.aspx?PageType=8&amp;ListId={8C0AC114-B19A-4CF7-B353-FC47A95E3D23}&amp;RootFolder=" onclick="javascript:NewItem2(event, 'https://thisCompany.com/HR/PerfRev/_layouts/listform.aspx?PageType=8&amp;ListId={8C0AC114-B19A-4CF7-B353-FC47A95E3D23}&amp;RootFolder=');return false;" target="_self">
<img src="../Images1/PGAT_Add_New.png" alt="AddNew" style="border-style: none; border-color: inherit; border-width: medium; float: left; width: 175px; height: 31px" />
0
$('#idHomePageNewItem').click(function(){
    var options = SP.UI.$create_DialogOptions();
    options.url = $(this).attr('href');
    SP.UI.ModalDialog.showModalDialog(options);
});

Use above function. Or change html as

<a class="ms-addnew" id="idHomePageNewItem" href="#" onclick="javascript:var options = SP.UI.$create_DialogOptions();options.url = 'https://thisCompany.com/HR/PerfRev/_layouts/listform.aspx?PageType=8&amp;ListId={8C0AC114-B19A-4CF7-B353-FC47A95E3D23}&amp;RootFolder=';SP.UI.ModalDialog.showModalDialog(options);" target="_self">
<img src="../Images1/PGAT_Add_New.png" alt="AddNew" style="border-style: none; border-color: inherit; border-width: medium; float: left; width: 175px; height: 31px" />
| improve this answer | |
0

You can open forms in a modal dialog by using SP.UI.ModalDialog.showModalDialog.

Here is the example code given from the site as well:

//Using the DialogOptions class.
var options = SP.UI.$create_DialogOptions();

options.title = "My Dialog Title";
options.width = 400;
options.height = 600;
options.url = "/_layouts/DialogPage.aspx";

SP.UI.ModalDialog.showModalDialog(options);

//Using a generic object.
var options = {
    title: "My Dialog Title",
    width: 400,
    height: 600,
    url: "/_layouts/DialogPage.aspx" };

SP.UI.ModalDialog.showModalDialog(options);

You essentially just need to give it the url and can play with the other options as needed.

| improve this answer | |

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.