Groping around in the DOM

S

Steve Swift

I have a page which contains a form. The forms name never changes (it's
called "SignOn"). I'd like to give the focus to the second element in
the form, a text INPUT field (as is the first). The name on these first
two elements changes regularly, so I'd like to set the focus without
coding the name, either by discovering the name of the element, or by
referring to the control some other way.

Is this possible?
 
S

Sister Ray

I have a page which contains a form. The forms name never changes (it's
called "SignOn").  I'd like to give the focus to the second element in
the form, a text INPUT field (as is the first).  The name on these first
two elements changes regularly, so I'd like to set the focus without
coding the name, either by discovering the name of the element, or by
referring to the control some other way.

Is this possible?

I think this will do the trick:
document.getElementById("for").getElementsByTagName("input")[0] for
the 1st
document.getElementById("for").getElementsByTagName("input")[1] for
the 2nd
 
G

Gregor Kofler

Steve Swift meinte:
I have a page which contains a form. The forms name never changes (it's
called "SignOn"). I'd like to give the focus to the second element in
the form, a text INPUT field (as is the first). The name on these first
two elements changes regularly, so I'd like to set the focus without
coding the name, either by discovering the name of the element, or by
referring to the control some other way.

Is this possible?

document.forms["SignOn"].elements[1].focus();

Gregor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top