Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1302 Is it possible to have one "submit" button activate two "onSubmits" in order for a form to be validated?

irt.org | Knowledge Base | JavaScript | Form | Q1302 [ previous next ]

Q1302 Is it possible to have one "submit" button activate two "onSubmits" in order for a form to be validated?

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>

Feedback on 'Q1302 Is it possible to have one "submit" button activate two "onSubmits" in order for a form to be validated?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.