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
Can the action be some custom validations?
If so and they fail, I would want the save process to stop. How's that done?
Is there an answer to the question above?
LW
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?
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>