By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,051 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Groping around in the DOM

P: n/a
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?

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Sep 22 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sep 22, 6:47*pm, Steve Swift <Steve.J.Sw...@gmail.comwrote:
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?

--
Steve Swifthttp://www.swiftys.org.uk/swifty.htmlhttp://www.ringers.org.uk
I think this will do the trick:
document.getElementById("for").getElementsByTagNam e("input")[0] for
the 1st
document.getElementById("for").getElementsByTagNam e("input")[1] for
the 2nd
Sep 22 '08 #2

P: n/a
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
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Sep 22 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.