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

Variable help

Status
Not open for further replies.

abshah

Programmer
Jul 29, 2000
14
US
I have a function that has one string parameter that contains a field name from a form. I would like to place focus on that field using the passed parameter. How do I do that?

For example:

function placeFocus(fieldname)
{
document.forms[0].+ fieldname + .focus();
}
 
I think you can use the fieldname as an index into the elements array like this:
Code:
document.formname.elements[fieldname].focus();
If that doesn't work, what you have above is on the right track, but you have to create a string out of it, and eval it. Like this:
Code:
eval("document.formname."+fieldname+".focus()");
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top