Javascript onchange event preventing onsubmit event in HTML form


Consider an HTML form:

<form action="" method="POST" onsubmit="return checkValidArray()">
    <input type="text" name="data" onchange="return validate(this);">

It appears (in both IE 6 and Firefox 3) that when you type some text into the input field and click submit that the onchange event fires for the input field, but the onsubmit event does not fire for the form until you click the submit button a second time (at which time the onchange does not fire, of course). In other words, the onchange seems to prevent the onsubmit from firing.

The desire is to check each field in the form when the user exits the field in order to provide them with immediate validation feedback, and also to prevent submission of the form if there is invalid data.

[EDIT: Note that both validation functions contain an alert().]

How does one get around this problem?

Best Solution

Solution (of a sort):

It turns out that it is only presence of an alert() - or a confirm() - during the input's onchange event that causes the form's onsubmit event to not fire. The JS thread appears to get blocked by the alert().
The workaround is to not include any alert() or confirm() in the input's onchange call.

Browsers known to be affected:
IE6 - Windows
IE8 - Win
FF3 - Win

Browsers known not to be affected:
Google Chrome - Win
Safari - Mac
FF - Mac