469,646 Members | 1,145 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

get the selected value of the asp:dropdownlist in javascript

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.selecte dIndex

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

Nov 18 '05 #1
1 11361
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
"Thierry" <Th*****@nospam.com> wrote in message
news:y8********************@phobos.telenet-ops.be...
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.selecte dIndex

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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by C | last post: by
1 post views Thread by Shapper | last post: by
reply views Thread by Barb | last post: by
3 posts views Thread by =?Utf-8?B?T2xkQnV0U3RpbGxMZWFybmluZw==?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.