JavaScript: Access DropDownList's current SelectedText value?

J

Jeremy

In client-side JavaScript, how does one retrieve into a variable the
currently displayed text in a DropDownList control.

I tried this, but it gets the current ID/value- not the displayed text:
var curText = document.all("DDLSomeList").value

This doesn't work either (although SelectedItem.Text works in code-behind):
var curText = document.all("DDLSomeList").SelectedItem.Text;

Thanks!
 
C

Craig Deelsnyder

In client-side JavaScript, how does one retrieve into a variable the
currently displayed text in a DropDownList control.

I tried this, but it gets the current ID/value- not the displayed text:
var curText = document.all("DDLSomeList").value

This doesn't work either (although SelectedItem.Text works in
code-behind):
var curText = document.all("DDLSomeList").SelectedItem.Text;

Thanks!
Try

var oDDL = document.all("DDLSomeList");
var curText = oDDL.options[oDDL.selectedIndex].text;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top