I need to get the value from a select list but JQuery is returning the text within the options of the select.
I have the following simple code.
<select id="myselect"> <option selected="selected">All</option> <option value="1">One</option> <option value="2">Two</option> </select> I then use the following JQuery, which I thought would get me the value
var myOption = $('#myselect').val() but when I look at myOption I get the text of 'One' or 'two'?
1or2but your are gettingoneandtwoinstead? If yes, I cannot reproduce your problem: jsfiddle.net/xmvFS. Make sure youroptionelements actually have avalueattribute or provide a demo. If it is vice versa and you want to get the text, it's a duplicate of stackoverflow.com/questions/196684/…myOptionanywhere else?