none
Redirect save/submit form to specific page RRS feed

  • Question

  • Hello,

    The code is validation condition for NewForm.apsx. I want redirect Url to  /ms/msg.aspx, when return true.

    script type="text/javascript" src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
     var j = jQuery.noConflict(); 
     function PreSaveAction() { 
      var txtTajuk = j(":input[id='ctl00_ctl43_g_2badfb10_0f5d_4a34_80a7_d6394bfd8198_ff11_ctl00_ctl00_TextField']").val();
      var txtPenerangan = j(":input[id='ctl00_ctl43_g_2badfb10_0f5d_4a34_80a7_d6394bfd8198_ff31_ctl00_ctl00_TextField']").val(); 
      var txtAgensi = j(":input[id='ctl00_ctl43_g_2badfb10_0f5d_4a34_80a7_d6394bfd8198_ff51_ctl00_DropDownChoice']").val(); 
     
    
       if(txtTajuk == ''){        
       alert("Sila masukkan Tajuk");          
       return false;
       }
       else if(txtPenerangan == ''){        
       	alert("Sila masukkan Penerangan");          
       	return false;
       }
       else if(txtAgensi == ''){        
       	alert("Sila pilih Agensi");          
       	return false;
       }
       
    	else {        
        window.open("/ms/msg.aspx","_self");         
       	return true;
       }
    
    }
      
    </script>
    

    Monday, January 8, 2018 10:14 AM

All replies

  • You can change the value of source url of the newitem. If you are using a direct link to new item, you can modify source url directly in that link or you can use javascript to change the sourceUrl on click of Save button:

    https://adrianhenke.wordpress.com/2010/08/19/custom-redirect-after-creating-a-new-sharepoint-item/ 

    Monday, January 8, 2018 1:21 PM
  • Hi,

    Here is sample script for your reference.

    <script type="text/javascript">
            function PreSaveAction() {
                if (window.location.href != "http://sp:12001/Lists/List2/NewForm.aspx?Source=http://sp:12001")
                    window.history.pushState('page2', 'Title', 'http://sp:12001/Lists/List2/NewForm.aspx?Source=http://sp:12001'); 
                return true;
            }
        </script> 

    While  window.history.pushState may not work properly in lower version of browser(I tested in my local with IE 10, working fine), and here is one thread for your reference.

    https://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page

     

    Best Regards,

    Lee


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


    Tuesday, January 9, 2018 9:22 AM