Retrieve and Set Select Tag Questions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MATTXtwo
    New Member
    • Sep 2006
    • 83

    Retrieve and Set Select Tag Questions

    I want to know how to retrive and set the selected value of select tag....
    I have use this code...
    Code:
    var Negeri=document.getElementById("State").options[document.getElementById("State").selectedIndex].text;
    So any ideas?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    That's the text of the option rather than the option value. Use the value property to get the value.

    A shortcut is to use:
    Code:
    document.getElementById("state").value
    for getting the value. To set the value, do you mean to change the value of a particular option, or do you mean changing the selected option to another one?

    Comment

    • MATTXtwo
      New Member
      • Sep 2006
      • 83

      #3
      Thanks acoder, Ihave already use the value property but some error get in the way first and I realize after debug the error and change the text property to value.....hah Half my day doin the same thing

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        So does that mean your problem's solved?

        Comment

        Working...