Radio button value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    Radio button value

    In my script I used to test the value of the radio button to verify which button was selected. I was able to do that because all the buttons have the same name. If I want to use the the proper
    Code:
    document.getElementById()
    notation.

    Will I have to:
    1) assign a unique id to each button
    2) test if that id is "checked"

    Or is it proper to use
    Code:
    document.getElementByName()
    and then test the value in the same manner I did before?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Yes, the IDs need to be unique, and yes, document.getEle mentsByName() is OK (don't forget the "s") and probably easier to deal with.

    Comment

    • Claus Mygind
      Contributor
      • Mar 2008
      • 571

      #3
      I really cannot get any of it to work.
      I use FireFox and any reference to
      Code:
      document.getElementByName()
      document.getElementByNames()
      document.getElementByTagName()
      generates an error "is not a function".

      Now I am trying with Id and giving a unique id to each button, hopefully that will work.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        There's no getElementByNam e() method, it's getElementsByNa me() - notice the difference (see link).

        Comment

        • Claus Mygind
          Contributor
          • Mar 2008
          • 571

          #5
          Thanks. That had been bothering me for awhile.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            You're welcome.

            Comment

            Working...