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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

focus on a element

Status
Not open for further replies.

ace21

Programmer
Joined
Jul 11, 2001
Messages
4
Location
US
I am trying to get the focus on an object if a condition occurs. Here is the code I am using. It will get the element.value right, but it doesn't focus on the element once the function exits.

function trigger(type,trigger,message, element)
{
switch (type)
{
case "number":
if (!isFloat(element.value))
{
window.alert(message);
element.focus();
}
break;
default:
document.alert("Fell through to default.");
}
}

Ace21
 
Try adding element.select() as well. Sometimes that helps keep the focus where you want it. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
What does the rest of the code look like?

What type of form element are you having trouble using focus() on? - tleish
 
tsDragon is correct!

You can use the select() method with the focus() method to highlight a field and position the cursor for a user response.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top