none
add new button on sharepoint page RRS feed

  • Question

  • hello,

    I want to provide "add new item" html button on a site page in sharepoint 2013. I have referred several articles on internet but none helped.

    When user clicks the button a modal dialog input form should open and upon submitting the data, it should redirect back to the page where the button was clicked instead of going to allitems.aspx page.

    Kindly help with js/html code.

    Friday, August 18, 2017 11:27 AM

Answers

  • Hi,

    The following code for your reference, create a wiki page or web part page, and add the code below(modify the "URL" to your new item from page URL of a list) into a content editor web part in the page.

    <input id="addnewitem" type="button" value="add new item" onclick="AddNewItem()"/>
    <script type="text/javascript">
         //******** Dialog with Data from Pop Up Starts Here ***********/
         function AddNewItem() {
             var options = {
                 url: '/sites/team/Lists/CustomList28/NewForm.aspx',
                 dialogReturnValueCallback: onPopUpCallBackWithData
             };
             SP.UI.ModalDialog.showModalDialog(options);
         }
      
         function onPopUpCallBackWithData(result, returnValue) {
             window.location.href=window.location.href;
         }  
     </script>
    

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by John.P.Smith Monday, August 21, 2017 11:25 AM
    Monday, August 21, 2017 2:51 AM
    Moderator

All replies

  • Hi,

    The following code for your reference, create a wiki page or web part page, and add the code below(modify the "URL" to your new item from page URL of a list) into a content editor web part in the page.

    <input id="addnewitem" type="button" value="add new item" onclick="AddNewItem()"/>
    <script type="text/javascript">
         //******** Dialog with Data from Pop Up Starts Here ***********/
         function AddNewItem() {
             var options = {
                 url: '/sites/team/Lists/CustomList28/NewForm.aspx',
                 dialogReturnValueCallback: onPopUpCallBackWithData
             };
             SP.UI.ModalDialog.showModalDialog(options);
         }
      
         function onPopUpCallBackWithData(result, returnValue) {
             window.location.href=window.location.href;
         }  
     </script>
    

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by John.P.Smith Monday, August 21, 2017 11:25 AM
    Monday, August 21, 2017 2:51 AM
    Moderator
  • Dennis, you are the savior !!

    Thank you so much. It's working perfectly. I really appreciate your help. :)

    Regards,

    prajk

    Monday, August 21, 2017 11:26 AM