Form inputs and their behaviors

So looks like someone needs to play a bit more with their form inputs. Marko reports that when he changed his form from:

<input type="button" />

to:

<input type="image" />

His forms started getting submitted automatically when clicking the image button. But yeah, that’s how it’s supposed to work. If that button is supposed to be your main “submit” like button on your form, then change your JavaScript code to trap the onSubmit event and return false to it. As in:

<form method="post" onSubmit="javascript:return handleXHR();"></form>

Then inside that function you just do “return false;” to stop the form from being submitted.

3 Comments »

  1. Marko said,

    January 26, 2006 @ 10:22 am

    I know, but what confused me was something else. It was that XHR handler was triggered by non-XHR event (at least that’s my explanation for an object that was missing most of XHR methods).

    It would be far more obvious what was happening if it didn’t.

  2. Joao Prado Maia said,

    January 26, 2006 @ 11:36 am

    On that case I’m not sure exactly what you are talking about. I was assuming that your XHR code was being triggered when someone clicked on that image button, but the form submission stuff was interfering with it.

  3. Marko said,

    January 26, 2006 @ 12:22 pm

    The problem was that clicking on image button executed javascript and submitted a form (as image buttons do), but because I was sloppy, I didn’t notice the later.

    The result was a weird error, which didn’t make sense. XHR handler that monitors state changes was executed without XHR actually having methods and parameters on which we rely upon. I don’t know why, but I’m guessing it was because of simultaneous form submition and XHR call, since the problem disappeared immediatelly after I cancelled form submittion.

    I’m sorry I wasn’t clear enough.

RSS feed for comments on this post · TrackBack URI

Leave a Comment