Wednesday, January 28, 2009

[jQuery] Re: onblur Firing Ahead Of onclick

Hi bob,

So it works exactly how I would expect that it should work.
1. the focus is taken from the input, so you get a blur event
2. the submit button is clicked, so you get a submit event

How about simply ignoring the blur event if you don't use it?
If you use it for data validation you would want do to it BEFORE you
submit the form, so the order
1. blur event -> data validation, set validation flag to true / false
2. submit event -> submit form if validation flag is true
makes sense for me.

by(e)
Stephan


2009/1/27 bob <xoxeonom@gmail.com>:
>
>
> jQuery('form[name=myForm]').bind('submit', validateForm);
> jQuery('#login').bind('focus', validateForm);
> jQuery('#blur').bind('blur', validateForm);
>
>
> Problem: when I click "login" text field and then "Submit" button
> what happens is that instead of
> alert('submit');
> I get
> alert('blur');
> What can I do about it? I need to have
> alert('submit'); triggered every time I click it.
>
>
> <form name="myForm" id="myForm" method="post" onsubmit="return
> false;">
> <input type="text" name="login" id="login">
> <input type="submit" value="Submit"/>
>
>
> function validateForm(e){
> if(e.type=='submit'){alert('submit');}
> if(e.type=='blur'){alert('blur');}
> }

No comments: