HighDots Forums  

Re: another newbie question - onblur / focus

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: another newbie question - onblur / focus in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Martin Honnen
 
Posts: n/a

Default Re: another newbie question - onblur / focus - 06-04-2005 , 08:00 AM








please-answer-here wrote:

Quote:
What is wrong with this code?

When I only assign the onblur call to one of the input fields everythings
work, but when I as belove use it on both fields I'll get an endless loop
with the alert messages repeating/replacing each other. I'll guess that the
problem/error must be somewhere in the focus expression but where is it?
It is well-known that using validation code in onblur handlers that
calls alert can trigger an endless loop of focus/blur events and thus
you should not use that. If you want to validate use the onsubmit
handler of the <form> element or if you really see a need to validate
each control after the user has input something then use the onchange
handler.

--

Martin Honnen
http://JavaScript.FAQTs.com/


Reply With Quote
  #2  
Old   
please-answer-here
 
Posts: n/a

Default Re: another newbie question - onblur / focus - 06-04-2005 , 09:10 AM






Martin Honnen wrote:
Quote:
please-answer-here wrote:

What is wrong with this code?

When I only assign the onblur call to one of the input fields
everythings work, but when I as belove use it on both fields I'll
get an endless loop with the alert messages repeating/replacing each
other. I'll guess that the problem/error must be somewhere in the
focus expression but where is it?

It is well-known that using validation code in onblur handlers that
calls alert can trigger an endless loop of focus/blur events and thus
you should not use that. If you want to validate use the onsubmit
handler of the <form> element or if you really see a need to validate
each control after the user has input something then use the onchange
handler.
Thanks for the information which for me as a newbie wasn't "well-known". If
I somehow want's to hold on to the logic which is that the user should be
informed on the error when leaving the field is there any options at all.
The onchange event I'll guess would not not trigger when leaving an
initially empty field.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.