get the selected value of the asp:dropdownlist in javascript

  • Thread starter Thread starter Thierry
  • Start date Start date
T

Thierry

Hi,

Is it possible to get the value of an asp:dropdownlist in javascript. I need
to get that value to assign it to a hyperlink.

This does not work:
document.FormEditCustomer.DDListVatCountry.selectedIndex

<script language="javascript">
function GetVatPopup()
{
VATCheck_window=window.open('VATCheck.aspx?VATNumber=' +
document.FormEditCustomer.TBVatNumber.value + '&VATCountry?' +
document.FormEditCustomer.DDListVatCountry.selectedIndex + '',
'VATCheck');VATCheck_window.focus()
}
</script>


Thanks,
Thierry
 
Thierry,

It renders as an HTML select element, so all the properties of the select
element are available on the client side. It does have a value property,
but this doesn't work reliably in all browsers. Using the option
represented by the selected index is a better general solution. e.g.:

var countrySelect = document.FormEditCustomer.DDListVatCountry;
if (countrySelect.selectedIndex > -1)
{
VATCheck_window = window.open('VATCheck.aspx?VATNumber=' +
document.FormEditCustomer.TBVatNumber.value + '&VATCountry?' +
countrySelect.options[countrySelect.selectedIndex].value,
'VATCheck');
VATCheck_window.focus();
}

If the VATCountry is represented in the display text of the option rather
than its value attribute, use the option's text property instead of its
value property.

HTH,
Nicole
 
Back
Top