JavaScript Form Submit Test

28 November 2005 · Last updated: 11 December 2006

Comments


Today I coded a form which disabled the submit button when the user pressed it. This was to avoid duplicate forms being processed, as can happen. The code is nothing new, but I tested it successfully in Opera 8.51 at first. Then I tried Internet Explorer 6. The button was disabled as expected, but then the page just stuck. After a long wait, an unusual JavaScript error message came up that I didn't understand. So I tried it in Firefox 1.5 RC3. The same. Opening the JavaScript console didn't reveal any errors (though it did catch one in my stylesheet, oddly enough). Hmmm, highly frustrating!

I gave up and removed the code. Only later did I realise I was coding it wrongly. I had put the JavaScript function call on the <input> element, but the form had another function call that occured on submit. D'oh!

It occured to me that since the code did work in Opera, Explorer was perhaps acting on the two clashing function calls in a different order. So I devised a test. The results are interesting in that Explorer seems to be the less capable browser when it comes to onmouseup. I've abandoned using that action before, due to problems in Explorer. In my test it actually stops the form from being submitted! Here is the test:

Submit Test

Click on the two input buttons and observe the results. The form also has an alert (pop-up message) when submitted. And yet the results vary between browsers. It may be useful to someone battling with JavaScript and forms to know this.

I recall once reading about Mozilla and Explorer differing in the way events bubble in JavaScript. This might explain the behaviour of my test.

I'd like to leave you with a summary of what I am getting on Windows XP. Your results may differ. If so, let me know.

  onmouseup onclick
Opera 8.51 Occurs last, after onsubmit Occurs first, then onsubmit
Firefox 1.5 RC3 Occurs first, then onsubmit Occurs first, then onsubmit
Internet Explorer 6 & 7 Occurs, but onsubmit doesn't! Occurs first, then onsubmit

Comments (1)

Comments are locked on this topic. Thanks to everyone who posted a comment.

  1. Nick Fitzsimons:
    Ah, another IE event peculiarity! I've been bitten a number of times by IE's strange ideas about event sequences - for example, IE 4 had a very odd sequence of blur/focus events when focusing form fields in different frames.
    For the purpose you describe, I would have probably have disabled the Submit button in the onsubmit handler, as there is a logical connection between the reason for disabling the button and the act of submitting the form. Using mousedown/mouseup events on the button could lead to unexpected effects if, say, the user pressed the mouse button on another element or a link, decided they didn't want to click on it after all, moved the mouse away (so as to cancel the click action on that element, but such that the pointer happened to be over the submit button) and then released the button again; I believe the button would then receive the mouseup event, even though the user had made no attempt to submit the form.

    Thanks for another post that I'll remember after driving myself mad debugging the selfsame problem in a few months :-)

    Posted on 17 January 2006 at 7:45 pm

Useful Info

EMAIL: www.designdetector.com (replace the 1st dot with "@")

NEWSFEED: Subscribe to news of fresh posts and site updates. (RSS 2.0 compatible newsreader required.)

Disclaimer

Some links on this website lead to information provided by external services not under my control, therefore I am not responsible for the content or accuracy of the linked information.

All code examples are not guaranteed 100% free from bugs and/or mistakes. Use them at your own risk. I do not take any blame should a problem occur relating to use of code on this site given as an example for your own use. Such code has been tested and found to work for me, but I cannot vouch for other computer systems (existing now, or in the future) which it may be used on, or changes you introduce yourself based on my code.

This website is © 2008 Christopher Hester, except where separate authors are named. No part of this website may be reproduced or re-used in any way without my prior permission, except content added from separate authors (who retain the copyright on their material), examples of code, and any other content I explicity state is free to copy and make use of.

This page was last updated on 11 December 2006.

What's New

Recent Finds


View previous finds


Current Reading

The Suspicions Of Mr Whicher (Or The Murder At Road Hill House) by Kate Summerscale
5%
Genesis: Chapter & Verse by Tony Banks, Phil Collins, Peter Gabriel, Steve Hackett & Mike Rutherford
70%
Digital Photographer's Handbook by Tom Ang
70%