Stretchwickster
Programmer
What I'm trying to do should be very simple. I'd like to assign a submit handler to a form and pass that form into the handler (I then wish to interrogate the id of the form argument and perform appropriate validation according to which form it is). The following code doesn't achieve the desired result. Inside the canSubmit function, according to firebug, the form argument seems to be of type form#[object HTMLInputElement] and form.id is undefined. As you can probably see I'm trying to implement this unobtrusively i.e. with behaviour separated into a separate js file. For information, I'm using jquery.
Any pointers would be much appreciated.
Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
Code:
// in domready event handler
$('form').submit(function() { return canSubmit(this); });
Code:
function canSubmit(form) {
switch(form.id) {
case "enhancementForm":
...
case "newitemForm":
...
}
return true;
}
Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096