Spaces/Official ESi/Scriptaculous & Adv. Tags

Carry out some actions when a board is saved

Andrew Donnan
posted this on November 25, 2008 15:25

This is an example of a script to carry out some action when a record is saved.

<script type="text/javascript">
function runWhenSubmitted() <--Give this a meaningful name, of course
{
[Do whatever processing you want here]
return;
}

function SetSubmitHandler()
{
document.forms[0].onsubmit = runWhenSubmitted;
}

window.onload = SetSubmitHandler;
</script>
 

Comments

User photo
Jim Shea
Johnson County

Can the action be some custom validations?

If so and they fail, I would want the save process to stop.  How's that done?

January 21, 2009 16:36
User photo
Louise Warner

Is there an answer to the question above?

LW

March 08, 2010 10:51
User photo
Sam Miller
TSA-P-RAC (STRAC - Southwest Texas RAC)

In your “runWhenSubmitted()” function have some “if” statements with your validation criteria, if the criteria fails the next line of code should be “return false;”. This should stop the save process. The only problem I see, is that if the cancel button is clicked it will still run the  “runWhenSubmitted()” function requiring certain criteria before canceling out of the form. Does anyone know a work around for this?

March 12, 2010 09:16
User photo
Tony Di Nino
Orange County (CA)

The solution is actually rather simple:  Don’t use the default buttons.  Instead, create your own as shown below.  Interestingly, the <returnbutton> tag will allow any value to be placed in the button whereas the <cancelbutton> tag will always default to “Cancel”.  So, just use the return button and call it “Cancel”.  Return will not execute any onsubmit code.  Both are in the example below.

 

<table>

        <tr>

                <td><input value="Save"></input></td>

                <td><returnbutton>Return</returnbutton></td>

                <td><returnbutton>Cancel</returnbutton></td>

                <td><printbutton></printbutton></td>

                 <td><pdflink >Print PDF</pdflink></td>

                <td><cancelbutton>This wording will not appear on the button</cancelbutton></td>

                <td style="display:none"><savebutton/></td>

        </tr>

</table>

 

April 01, 2010 16:45