Groping around in the DOM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Swift

    #1

    Groping around in the DOM

    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


  • Sister Ray

    #2
    Re: Groping around in the DOM

    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.getEle mentById("for") .getElementsByT agName("input")[0] for
    the 1st
    document.getEle mentById("for") .getElementsByT agName("input")[1] for
    the 2nd

    Comment

    • Gregor Kofler

      #3
      Re: Groping around in the DOM

      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

      Comment

      Working...