Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<select id="ddlViewBy">
<option value="1">test1</option>
<option value="Father" >A</option>
<option value="Son">B</option>
<option value="Son">C/option>
</select>


how to get "test3" through java script like ((DropDownList)plc1.FindControl(CtrID)).SelectedItem.Text

Thanks
Posted
Updated 18-Nov-15 23:25pm
v2

You can use
JavaScript
var e = document.getElementById("ddlViewBy");
var value = e.options[e.selectedIndex].value;
var text = e.options[e.selectedIndex].text;
 
Share this answer
 
JavaScript:
var t = document.getElementById("ddlViewBy");<br />
var selectedText = t.options[t.selectedIndex].text;


jQuery:
Optimized:
$("#ddlViewBy option").is("selected").text();
Fastest:
$("#ddlViewBy").children("option").is("selected").text();

-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900