Marc Davis
asked on
ASP.NET DropDown list item text from JavaScript?
I have a ASP.NET DrownDown and I need get the selectedItem.Text from JavaScript.
How can I achieve that? Any examples would be great so I have a clear/concise understanding.
Any assistence would be greatly appreciated.
How can I achieve that? Any examples would be great so I have a clear/concise understanding.
Any assistence would be greatly appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked like a charm and thank you very, very much. I didn't realize one could use the getElementByID on the document as well.
I also found that this works as well:
var oDDL = document.all("ctl00_cphBod y_DropDown List");
var curText = oDDL.options[oDDL.selected Index].tex t;
As you can see by this there is a Masterpage.
But you're solution worked out in a excellent fashion as well.
Thanks and much appreciated.
I also found that this works as well:
var oDDL = document.all("ctl00_cphBod
var curText = oDDL.options[oDDL.selected
As you can see by this there is a Masterpage.
But you're solution worked out in a excellent fashion as well.
Thanks and much appreciated.
Glad to help :)
If master page is used we can use ClientID to get the control.
If master page is used we can use ClientID to get the control.
ASKER
On the other variation that I found that worked as well?
Because I tried this:
var oDDL = document.all(document.getE lementById ('<%=DropD ownList1.C lientID%>' );
var curText = oDDL.options[oDDL.selected Index].tex t;
But that did not work.
Because I tried this:
var oDDL = document.all(document.getE
var curText = oDDL.options[oDDL.selected
But that did not work.
To get id of control we have to use '<%=DropDownList1.ClientID %>'
document.getElementById('< %=DropDown List1.Clie ntID%>') will return object.
Below one will work.
var oDDL = document.all('<%=DropDownL ist1.Clien tID%>');
var curText = oDDL.options[oDDL.selected Index].tex t;
document.getElementById('<
Below one will work.
var oDDL = document.all('<%=DropDownL
var curText = oDDL.options[oDDL.selected
ASKER
You're right, that would have brought back the object. Don't know what I was thinking except for many things at a time. :-)
Yep, that worked. I thought I did that before and it didn't work.
Not too sure what I did but it worked and thanks again.
Yep, that worked. I thought I did that before and it didn't work.
Not too sure what I did but it worked and thanks again.
Open in new window