code_junkie

How to get DataTextField of DropDownList in javascript?

Nov 13th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <asp:DropDownList
  2. ID="ddlLocationName"
  3. runat="server"
  4. DataValueField="Guid"
  5. DataTextField="LocationName"
  6. AppendDataBoundItems="false"
  7. AutoPostBack="false"
  8. onchange="LocationChange()"
  9. ></asp:DropDownList>
  10.  
  11. function LocationChange()
  12. {
  13. document.getElementById ("ctl00_mainContent_ctl02_txtEventLocation").value = document.getElementById ('ctl00_mainContent_ctl02_ddlLocationName')[document.getElementById ('ctl00_mainContent_ctl02_ddlLocationName').selectedIndex].value
  14. }
  15.  
  16. function LocationChange(){
  17. var ddl = $get('dropDownListId');
  18. var selectedOption = ddl.options[ddl.selectedIndex];
  19. var selectedText = selectedOption.text;
  20. var selectedValue = selectedOption.value;
  21.  
  22. alert('Your option has a text property of ' + selectedText + ' and a value property of ' + selectedValue');
  23. }
  24.  
  25. function LocationChange()
  26. {
  27. document.getElementById ("ctl00_mainContent_ctl02_txtEventLocation").value = document.getElementById ('ctl00_mainContent_ctl02_ddlLocationName')[document.getElementById ('ctl00_mainContent_ctl02_ddlLocationName').selectedIndex].innerText
  28. }
Add Comment
Please, Sign In to add comment