Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

element.focus() doesnot work 1

Status
Not open for further replies.

brianpercival

Programmer
Jun 13, 2005
63
US
I have a text field with onchange function. in the function I check if it is valid if not I say field.focus.

like

var f1=theform.f1;

if (f1.value blah blah) alert

f1.focus

return

when I enter invalid data and select next field, it alerts me about the invalid data but focus goes to the "next" field. what am I doing wrong?

regards,
Brian
 
It's probably a timing issue. Instead of this:

Code:
f1.focus();

try this:

Code:
setTimeout('document.forms[\'theform\'].elements[\'f1\'].focus();', 100);

to give a short delay before focussing.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
BillyRay.. Thanks a lot.. It worked. I have been raking my brains over it.

btw, javascript section of tek-tips is by far the section with least response time.

Also can anyone plz give me a good comprehensive link to learn javascript?

regards,
Brian
 
javascript section of tek-tips is by far the section with least response time.
That's cause we're always scrambling to get to get the star first
(which you didn't give to Dan, tsk tsk)

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
so stars are the reason
Not for everybody, myself not included.

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Yeah, I'm gonna have to see if I can lobby to get them put on the site as a shortcut. I could see how they wouldn't be appropriate, but no more so than [rockband]: [rockband]

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top