[jQuery] Re: event coordination problem
Ahh. The problem is that there is NO relation between the two fields: they're just DOM elements like divs, paragraphs, and iframes. The blur event of some textbox is _totally_ unrelated to a click event of some other button. If you want to enforce some rules between the two you'll have to code it yourself - the usual way is to check each individual field on blur and when you click the button, re-check all validation rules. There are also heaps of validation plugins in the jQuery plugin repository you might like to look at to simplify validation handling. On Sep 14, 12:28 pm, Rick Faircloth r...@whitestonemedia.com wrote: if you put the focus in the textbox (#id1) then click the button (#id2) both events get fired Jim... Preventing this occurrence is what I was talking about. What I do is keep the submit button disabled until all required fields have been validated on blur. That way you can't have a field that hasn't been validated and have the submit button fire, too. The user has to blur out of the field to achieve validation and enabling of the submit button. Am I misunderstanding? Rick -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Mr Speaker Sent: Sunday, September 13, 2009 10:07 PM To: jQuery (English) Subject: [jQuery] Re: event coordination problem I pasted your code into a new HTML doc and it ran as expected: if you put the focus in the textbox (#id1) then click the button (#id2) both events get fired (blur event fires first, click event fires second). Is there anything else in your page? Are you getting any JS errors? On Sep 13, 4:27 am, jhm jmay...@gmail.com wrote: Not sure how this helps, and in fact I'm pretty much already doing that. The problem is that if the focus is in the field, when the button is clicked I get the blur event only and not the click event on the button. If you try the code in the OP, you'll see this happening. Remember to click into the text box before clicking on the button. I need the click event for sure. I could live without the blur event in this situation, but I'd also like to understand the dynamics of what is happening for the future. Jim On Sep 12, 10:39 am, Rick Faircloth r...@whitestonemedia.com wrote: How about setting the field to invalid to start with and force the user to blur the field for a validation routine to declare it valid. Rick -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of jhm Sent: Saturday, September 12, 2009 1:04 PM To: jQuery (English) Subject: [jQuery] event coordination problem Hi- In a form, I'm trying to validate a field when they move off it. But this causes a problem when the field has the focus and they click a button to process the form. In this case, only the field's blur event (or change event) gets fired and nothing for the button click event. Seems like a reasonable thing to want to do, so I figure I'm missing something in they way I've coded this. Any suggestions? Here's the very simple code that exhibits the behavior: head script type=text/javascript src=./js/jquery.js/script script type=text/javascript $(document).ready( function() { $('#id1').blur( function() { alert('blur in id1'); }); $('#id2').click( function() { alert('click in id2'); }); }); /script /head body /body input type=text value=Sample Text name=id1 id=id1 / input type=button name=Finish value=Finish id=id2 / /html
[jQuery] Re: event coordination problem
I pasted your code into a new HTML doc and it ran as expected: if you put the focus in the textbox (#id1) then click the button (#id2) both events get fired (blur event fires first, click event fires second). Is there anything else in your page? Are you getting any JS errors? On Sep 13, 4:27 am, jhm jmay...@gmail.com wrote: Not sure how this helps, and in fact I'm pretty much already doing that. The problem is that if the focus is in the field, when the button is clicked I get the blur event only and not the click event on the button. If you try the code in the OP, you'll see this happening. Remember to click into the text box before clicking on the button. I need the click event for sure. I could live without the blur event in this situation, but I'd also like to understand the dynamics of what is happening for the future. Jim On Sep 12, 10:39 am, Rick Faircloth r...@whitestonemedia.com wrote: How about setting the field to invalid to start with and force the user to blur the field for a validation routine to declare it valid. Rick -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of jhm Sent: Saturday, September 12, 2009 1:04 PM To: jQuery (English) Subject: [jQuery] event coordination problem Hi- In a form, I'm trying to validate a field when they move off it. But this causes a problem when the field has the focus and they click a button to process the form. In this case, only the field's blur event (or change event) gets fired and nothing for the button click event. Seems like a reasonable thing to want to do, so I figure I'm missing something in they way I've coded this. Any suggestions? Here's the very simple code that exhibits the behavior: head script type=text/javascript src=./js/jquery.js/script script type=text/javascript $(document).ready( function() { $('#id1').blur( function() { alert('blur in id1'); }); $('#id2').click( function() { alert('click in id2'); }); }); /script /head body /body input type=text value=Sample Text name=id1 id=id1 / input type=button name=Finish value=Finish id=id2 / /html
[jQuery] Re: event coordination problem
if you put the focus in the textbox (#id1) then click the button (#id2) both events get fired Jim... Preventing this occurrence is what I was talking about. What I do is keep the submit button disabled until all required fields have been validated on blur. That way you can't have a field that hasn't been validated and have the submit button fire, too. The user has to blur out of the field to achieve validation and enabling of the submit button. Am I misunderstanding? Rick -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Mr Speaker Sent: Sunday, September 13, 2009 10:07 PM To: jQuery (English) Subject: [jQuery] Re: event coordination problem I pasted your code into a new HTML doc and it ran as expected: if you put the focus in the textbox (#id1) then click the button (#id2) both events get fired (blur event fires first, click event fires second). Is there anything else in your page? Are you getting any JS errors? On Sep 13, 4:27 am, jhm jmay...@gmail.com wrote: Not sure how this helps, and in fact I'm pretty much already doing that. The problem is that if the focus is in the field, when the button is clicked I get the blur event only and not the click event on the button. If you try the code in the OP, you'll see this happening. Remember to click into the text box before clicking on the button. I need the click event for sure. I could live without the blur event in this situation, but I'd also like to understand the dynamics of what is happening for the future. Jim On Sep 12, 10:39 am, Rick Faircloth r...@whitestonemedia.com wrote: How about setting the field to invalid to start with and force the user to blur the field for a validation routine to declare it valid. Rick -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of jhm Sent: Saturday, September 12, 2009 1:04 PM To: jQuery (English) Subject: [jQuery] event coordination problem Hi- In a form, I'm trying to validate a field when they move off it. But this causes a problem when the field has the focus and they click a button to process the form. In this case, only the field's blur event (or change event) gets fired and nothing for the button click event. Seems like a reasonable thing to want to do, so I figure I'm missing something in they way I've coded this. Any suggestions? Here's the very simple code that exhibits the behavior: head script type=text/javascript src=./js/jquery.js/script script type=text/javascript $(document).ready( function() { $('#id1').blur( function() { alert('blur in id1'); }); $('#id2').click( function() { alert('click in id2'); }); }); /script /head body /body input type=text value=Sample Text name=id1 id=id1 / input type=button name=Finish value=Finish id=id2 / /html
[jQuery] Re: event coordination problem
How about setting the field to invalid to start with and force the user to blur the field for a validation routine to declare it valid. Rick -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of jhm Sent: Saturday, September 12, 2009 1:04 PM To: jQuery (English) Subject: [jQuery] event coordination problem Hi- In a form, I'm trying to validate a field when they move off it. But this causes a problem when the field has the focus and they click a button to process the form. In this case, only the field's blur event (or change event) gets fired and nothing for the button click event. Seems like a reasonable thing to want to do, so I figure I'm missing something in they way I've coded this. Any suggestions? Here's the very simple code that exhibits the behavior: head script type=text/javascript src=./js/jquery.js/script script type=text/javascript $(document).ready( function() { $('#id1').blur( function() { alert('blur in id1'); }); $('#id2').click( function() { alert('click in id2'); }); }); /script /head body /body input type=text value=Sample Text name=id1 id=id1 / input type=button name=Finish value=Finish id=id2 / /html
[jQuery] Re: event coordination problem
Not sure how this helps, and in fact I'm pretty much already doing that. The problem is that if the focus is in the field, when the button is clicked I get the blur event only and not the click event on the button. If you try the code in the OP, you'll see this happening. Remember to click into the text box before clicking on the button. I need the click event for sure. I could live without the blur event in this situation, but I'd also like to understand the dynamics of what is happening for the future. Jim On Sep 12, 10:39 am, Rick Faircloth r...@whitestonemedia.com wrote: How about setting the field to invalid to start with and force the user to blur the field for a validation routine to declare it valid. Rick -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of jhm Sent: Saturday, September 12, 2009 1:04 PM To: jQuery (English) Subject: [jQuery] event coordination problem Hi- In a form, I'm trying to validate a field when they move off it. But this causes a problem when the field has the focus and they click a button to process the form. In this case, only the field's blur event (or change event) gets fired and nothing for the button click event. Seems like a reasonable thing to want to do, so I figure I'm missing something in they way I've coded this. Any suggestions? Here's the very simple code that exhibits the behavior: head script type=text/javascript src=./js/jquery.js/script script type=text/javascript $(document).ready( function() { $('#id1').blur( function() { alert('blur in id1'); }); $('#id2').click( function() { alert('click in id2'); }); }); /script /head body /body input type=text value=Sample Text name=id1 id=id1 / input type=button name=Finish value=Finish id=id2 / /html