I have a custom Edit form in SP2013 where I want the Save button to do two things:

  1. Commit changes
  2. Call JavaScript function

The function in step #2 does several things including a workflow trigger. What I've done is hide the OOTB save button and create my own like so:

<input type="button" value="Send" onclick="javascript: {ddwrt:GenFireServerEvent('__commit')}; SendProject('http://site.com/subsite/Lists/Projects/{@ID}_.000');"/>

I think I'm close, but currently it's committing the changes then nothing. The form doesn't close and the second function never starts. I've tried it with and without the "javascript" identifier in front of the second function. Either call works by itself, so the issue is how I'm calling one after the other.

I also tried wrapping both in a function and calling the function on click, but the GenFireServerEvent doesn't seem to work from JavaScript.

After a few Google searches, I've found a couple of close ones, but no working solution yet. Any ideas what I'm doing wrong?

  • 1
    Your button is performing a post back to the server. Your form is reloading, and your page context is lost. What you want is a PostSaveAction(), which unfortunately does not exist. You have a couple options here. You can make your changes using Ajax, – Derek Gusoff Jul 11 '14 at 15:05
  • 3
    sorry, premature enter button hit. The other option is to do some sort of redirect to a new page where your second function executes, using the Source parameter. sympmarc.com/2009/10/20/… – Derek Gusoff Jul 11 '14 at 15:07
  • @DerekGusoff - I ended up using the redirect idea. If you want to add that as an answer, I'll accept it. – Omegacron Jul 14 '14 at 13:18
  • I'm glad you found a solution to this. I'll post an answer when I get time. – Derek Gusoff Jul 14 '14 at 18:07

There is a JavaScript function in SharePoint called "PreSaveAction" that is fired just before the item is validated and saved. You can use this function to call your function. For example:

function PreSaveAction(){
    return true;

I've used PreSaveAction before for client side form validation and creating items in a different list. Please note, you might need to do your own validation because if the item fails server side validation your function will have run but the item will not be saved (causing the user to fix the validation error, hit save again, and running your function again).

| improve this answer | |

Use your custom button to click the OOTB send button after you do whatever you want to do.

<input type="button" value="My Send" onclick="SendProject('http://site.com/subsite/Lists/Projects/{@ID}_.000');$('input[value=Send]').click();" />    
<input type="button" value="Send" onclick="javascript: {ddwrt:GenFireServerEvent('__commit')};" style="display:none" />

Not sure what your SendProject function does, but if you want to make sure it completes you can make it an ajax call and on the success click the OOTB button.

| improve this answer | |
  • Actually, I want to do it the other way around - commit the changes (OOTB button) THEN work my magic. – Omegacron Jul 11 '14 at 21:06

This does the trick


You can add this code to button click event, don't forget referencing jquery library if you are adding in CE web part.

| improve this answer | |
  • This is not what the OP wants. OP wants to perform some action after the form is saved. – NLV Nov 10 '16 at 17:21

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.