Forum Moderators: open

Message Too Old, No Replies

Dual Event Handlers

Using two onclick event handlers in same tag

         

typomaniac

11:15 am on Feb 15, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi, is there any way to use 2 of the same event handler in the same tag...that is, I would like to use a submit once script and a form validation script and both call for an onclick handler in the form tag. I have server side validation as backup but javascript can take place so much faster. Also, if it is possible, will the button for the submit once script still be in effect if used this way and the script finds an error in user input? Thanks.

typomaniac

2:27 pm on Feb 15, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



I apologize for the error I made when submitting....it should be onSubmit instead of onclick

Fotiman

3:24 pm on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can just wrap the 2 functions that you want to execute in a third function (even a self executing anonymous one):

<form onsubmit="return function () {if (!validate()) {return false;} submitonce(); return true; }();">

or

<form onsubmit="return formOnSubmit();">

with

function formOnSubmit() {
if (!validate()) {
return false;
}
submitOnce();
return true;
}