You are here: irt.org | FAQ | JavaScript | Form | Q1302 [ previous next ]
There is only one onSubmit event handler per form. But it can do more than one thing:
<form onSubmit="action1;action2;action3">
If you want the onSubmit event handler to invoke a funtion to validate form data, then ensure that the function returns true (valid data) or false (invalid data) and then return the result in the onSubmit handler:
<form onsubmit="return function1()">
To invoke two funtions and combine the results ue:
<form onSubmit=" return (function1() && funtion2())">
When you hit a submit button the onSubmit event handler invoked.
You can also submit a form using JavaScript, e.g.:
<form name="myForm" onSubmit="function1()"> </form> <script language="JavaScript"><!-- document.myForm.submit(); //--></script>
However, the onSubmit event handler will NOT not invoked, but you can always invoke it yourself:
<script language="JavaScript"><!-- if (function1()) document.myForm.submit(); //--></script>
Likewise, you could invoke two functions to validate your form:
<script language="JavaScript"><!-- if (function1() && function2()) document.myForm.submit(); //--></script>
Note, that in the last example, if function1() returns false function2() will not be invoked.
To add this to your own "submit" button use:
<form name="myForm"> <imput type="button" value="Submit" onClick="if (function1() && function2()) document.myForm.submit();"> </form>