how to get text of select tag when you know value of that text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Trisha8
    New Member
    • Feb 2013
    • 7

    how to get text of select tag when you know value of that text

    i have a string variable which contain value. now i want to access text to which this value belongs.
    Any idea??
    Code:
    <select>
      <option value="v">Volvo</option>
      <option value="s">Saab</option>
      <option value="m">Mercedes</option>
      <option value="a">Audi</option>
    </select>
    suppose variable=v then i should be able to alert 'Volvo'.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    If it's not the selected option, you will need to loop over the options array and get the text property.
    Code:
    elem.options[index].text
    If you use jQuery, for example, you could use something like
    Code:
    $("#elem option[value='v']").text()

    Comment

    Working...