Here is a link to a simple test page to illustrate my issue:
I have a form field in which when you enter a username it calls an AJAX post method to call a server side script to check the username is unique. This is all working fine.
Hence if you type the username "olduser" then click on the "Your name" field, you will see the blur event gets triggered and a message notifying that the username is already taken is displayed. The additional "UsernameUnique" is just a variable to show a flag has been set.
Now please click on http://www.dressorganic.co.uk/blurtest/
again and add "olduser" to the username but instead of clicking on "Your name" go straight to clicking the save button. You will notice from the alerts that the form submission gets handled first followed by the blur event handler. Unfortunately the blur event sets the "UsernameUnique" flag which the submit handler is supposed to look at. Hence the submit handler does not see UsernameUnique = false so the form gets submitted.
Can somebody please explain how I can make the blur handler get called first followed by the submit handler? Alternatively if there is a better way to handle this then please explain.