How do you get the text value of a selected option?

Answer

Select elements typically have two values that you want to access. First there's the value to be sent to the server, which is easy:

 $("#pcdsselect").val();
 // => 1

The second is the text value of the select. For example, using the following select box:

 <select id="pcdsselect">

   <option value="1">Mr</option>
   <option value="2">Mrs</option>
   <option value="3">Ms</option>
   <option value="4">Dr</option>

   <option value="5">Prof</option>
 </select>

If you wanted to get the string "Mr" if the first option was selected (instead of just "1"), you would do that in the following way:

 $("#mpcdsselect option:selected").text();
 // => "Mr"

All JQUERY Questions

Ask your interview questions on jquery

Write Your comment or Questions if you want the answers on jquery from jquery Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---