my dog learned polymorphism
The moose likes HTML, CSS and JavaScript and the fly likes retain textbox focus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "retain textbox focus" Watch "retain textbox focus" New topic

retain textbox focus

sriram viswanathan

Joined: Jul 27, 2007
Posts: 12
What is the best way to retain textbox focus when a validation fails?
Scenario: Txt1 and Txt2 are next to each other. Both are mandatory fields. When we write code in Txt1 onblur, it fires only after yielding focus to Txt2. This causes a problem because, when we do Txt1.focus from onblur, it fires the Txt2 onblur, which in turn requests focus, thus going into a deadlock situation.

To avoid this, had to go for a dirty flag as in the code snippet below.

Is there a better way? Are there any good events that will work in IE as well as Firefox?

Note: Also tried
return false
inside onblur. Dint work.

Thanks in advance,
[ September 10, 2008: Message edited by: sriram viswanathan ]

Thanks,<br />Sriram
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63355

"sriram", please check your private messages for an important administrative matter.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: retain textbox focus
It's not a secret anymore!