Thursday, September 18, 2014

How do I get the text value of a selected option

Consider following option control to get the selected value and the text from jQuery. Same functionality can be done using javascripts. For more information please refer  Get asp.net drop down list Selected value and text using javascript.

<select id="drpControl">
    <option value="1">Mr</option>
    <option value="2">Mrs</option>
    <option selected="true" value="3">Ms</option>
    <option value="4">Dr</option>
    <option value="5">Prof</option>
</select>

If you want to get the selected string "Ms", you would do that in the following way:
$("#drpControl option:selected").text();
// returns Ms

If you want to get the selected value of "Ms", you would do that in the following way:
$("#drpControl option:selected").Val();
// returns 3

1 comment:

  1. Such an ideal piece of blog. It’s quite interesting to read content like this. I appreciate your blog

    Thanks for sharing this information! I totally agree with you. Your information is very interesting and important. I really like this information.

    ReplyDelete