Overwrite Default Source URL With Custom URL In SharePoint OOTB Save Button In Edit Form Using jQuery - SharePoint Online

In this blog, you will learn about steps to overwrite the default source URL in edit form with custom URL.

Today, we will explore the process of replacing the default source URL of the OOTB Save button in EditForm with our custom URL. For this, we have to modify the "PreSaveItem" function in the Save button.
 
Code Usage
  1. <script type="text/javascript">  
  2.     $(document).ready(function() {  
  3.   
  4.         var elementName;  
  5.         var oldPostbackUrl;  
  6.         var currentSourceValue;  
  7.         var newPostbackUrl;  
  8.         var button = $("input[id$=SaveItem]");  
  9.   
  10.         // change redirection behavior  
  11.         button.removeAttr("onclick");  
  12.   
  13.         button.click(function() {  
  14.             var elementName = $(this).attr("name");  
  15.             var aspForm = $("form[id=aspnetForm]");  
  16.             oldPostbackUrl = aspForm[0].action;  
  17.             currentSourceValue = GetUrlKeyValue("Source"true,  
  18.                 oldPostbackUrl);  
  19.    
  20.             var redirectURL = _spPageContextInfo.webAbsoluteUrl + "/Pages/RoleIn.aspx";  
  21.             newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, redirectURL);  
  22.   
  23.             if (!PreSaveItem()) return false;  
  24.   
  25.             WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, ""true"", newPostbackUrl, falsetrue));  
  26.     
  27.         });  
  28.   
  29.     }); 
  30. </script>  
Please feel free to share your comments.
 
Hope this helps!!!!!