By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

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

P: 7
i have a string variable which contain value. now i want to access text to which this value belongs.
Any idea??
Expand|Select|Wrap|Line Numbers
  1. <select>
  2.   <option value="v">Volvo</option>
  3.   <option value="s">Saab</option>
  4.   <option value="m">Mercedes</option>
  5.   <option value="a">Audi</option>
  6. </select> 
suppose variable=v then i should be able to alert 'Volvo'.
Mar 13 '13 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
If it's not the selected option, you will need to loop over the options array and get the text property.
Expand|Select|Wrap|Line Numbers
  1. elem.options[index].text
If you use jQuery, for example, you could use something like
Expand|Select|Wrap|Line Numbers
  1. $("#elem option[value='v']").text()
Mar 13 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.