Click to See Complete Forum and Search --> : onBlur & onClick fight


Gerry
09-11-2003, 10:35 AM
Hi -

I have a textarea with an onBlur event to check the length of the text entered. If the text is too long, an alert tells the user so but lets him continue on his way editing other form fields. (This is the desired action). I attempted to call the same javascript function when the button that submits the form is clicked and so it does so and returns false so that the page cannot submit when too much text has been entered. Again, this is the desired action, but I encountered a problem in Netscape. If the last form field the cursor was in was the textarea, the onBlur event fires when the submit button is clicked because the focus is being lost, then it submits again because the page is being submitted. The effect is that the user gets two of the same error message alert windows one after another.

Is there a way I can check in the onBlur event to see if the submit button is the object I'm blurring to, and if so refrain from showing the alert? Alternatively, is there a way the onSubmit event (or onClick event) can know whether or not the onBlur event just finished showing the same message?

Thanks

zachzach
09-12-2003, 07:00 PM
get rid of the onblur and onclick checks, now just add a function that checks them all to the ""submit button"" (make it fake)

then if its correct, at the end of the function:

if(correct<!--however you check it-->) {
document.nameoftheform.submit()
}

that should work
zach