I eventually found that the problem was nothing to do with the code I
posted. I'd unwittingly set the id and name attributes of one of my
form elements to "id". So, when I was checking form.id it was
returning an object representing the form element rather than giving
me the id of the form!

On Feb 17, 9:20 am, stretch <clive.wick...@gmail.com> wrote:
> Yes, I was hoping to do this unobtrusively, keeping all my behaviour
> in a separate js file to keep the XHTML clean. Sorry, I should have
> mentioned that's what I was aiming for in my original post.
>
> Any other ideas?
>
> On Feb 16, 7:17 pm, Michael Lawson <mjlaw...@us.ibm.com> wrote:
>
> > Is there a reason you can just use the onsubmit event?
>
> > <form id="blah" action="blah" onsubmit="canSubmit(this)">
>
> > something like that
>
> > cheers
>
> > Michael Lawson
> > Content Tools Developer, Global Solutions, ibm.com
> > Phone:  1-919-517-1568 Tieline:  255-1568
> > E-mail:  mjlaw...@us.ibm.com
>
> > 'Examine my teachings critically, as a gold assayer would test gold. If you
> > find they make sense, conform to your experience, and don't harm yourself
> > or others, only then should you accept them.'
>
> >   From:       stretch <clive.wick...@gmail.com>                             
> >                                      
>
> >   To:         "jQuery (English)" <jquery-en@googlegroups.com>               
> >                                      
>
> >   Date:       02/16/2009 02:15 PM                                           
> >                                      
>
> >   Subject:    [jQuery] Pass form as argument into its submit event          
> >                                       
>
> > What I'm trying to do should be very simple. I would 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.
>
> > // in domready event handler
> > $('form').submit(function() { return canSubmit(this); });
> > ...
> > function canSubmit(form) {
> >   switch(form.id) {
> >     case "enhancementForm":
> >     ...
> >     case "newitemForm":
> >     ...
> >   }
> >   return true;
>
> > }
>
> > Any pointers would be much appreciated.
>
> > Clive
>
> >  graycol.gif
> > < 1KViewDownload
>
> >  ecblank.gif
> > < 1KViewDownload

Reply via email to