get the selected value of the asp:dropdownlist in javascript

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
 
N

Nicole Calinoiu

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
 
Joined
May 1, 2007
Messages
1
Reaction score
0
Getting dropdown selected value using javascript

Hi..

The following javascript method retrieve the dropdown selected value:

function getDropDownListvalue()
{
var IndexValue = $get('<%=DropDown1.ClientID %>').selectedIndex;
var SelectedVal = $get('<%=DropDown1.ClientID %>').options[IndexValue].value;
alert(SelectedVal);
}

-Thanks,
HaPpy CoDiNg 8)
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top