Javascript: Refer to element within DIV tag

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ChrisPintys
    New Member
    • Aug 2010
    • 20

    Javascript: Refer to element within DIV tag

    Hey,

    I have a form, and I'm working on validation, half way through the form, I have a <DIV> tag that contains the rest of the elements in the form, it seems I can access the elements before the <DIV> tag, but not after, after googling I've found the getelementbyID function, but not sure if it will do what I want. Picture something like this:

    Code:
    <form>
    <input id="test" name="test">
    <div id="myDiv">
    <input id="test2" name="test2">
    </div>
    </form>
    I have some javascript referring to the test element with no issues, but if I try to refer to test2, it doesn't work. How would I go about referring to test2 when it's within a DIV?

    As you can tell, I'm very new to this.

    Thanks.
  • pradeepkr13
    New Member
    • Aug 2010
    • 43

    #2
    document.getEle mentById('test2 ').name
    document.getEle mentById('test2 ').value
    document.getEle mentById('test2 ').id

    Comment

    • pradeepkr13
      New Member
      • Aug 2010
      • 43

      #3
      There are many ways to access form objects rather.
      Without even using getElementById( ). Check this.

      Comment

      • ChrisPintys
        New Member
        • Aug 2010
        • 20

        #4
        Thanks! That helped out lots, I got it working.

        Comment

        Working...