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
- <script type="text/javascript">
- $(document).ready(function() {
-
- var elementName;
- var oldPostbackUrl;
- var currentSourceValue;
- var newPostbackUrl;
- var button = $("input[id$=SaveItem]");
-
-
- button.removeAttr("onclick");
-
- button.click(function() {
- var elementName = $(this).attr("name");
- var aspForm = $("form[id=aspnetForm]");
- oldPostbackUrl = aspForm[0].action;
- currentSourceValue = GetUrlKeyValue("Source", true,
- oldPostbackUrl);
-
- var redirectURL = _spPageContextInfo.webAbsoluteUrl + "/Pages/RoleIn.aspx";
- newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, redirectURL);
-
- if (!PreSaveItem()) return false;
-
- WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
-
- });
-
- });
- </script>
Please feel free to share your comments.
Hope this helps!!!!!