views:

55

answers:

1

Does anyone know how to get the values from an asp dropdownbox (not just the selected one) using javascript?

+5  A: 

Assuming you mean a <select> element - just loop over its options property.

var options = refToMyForm.elements.mySelect.options;
for (var i = 0, j = options.length; i < j; i++) {
    var option = option[i];
    var value = option.value;
}
David Dorward
actually, an <asp:DropDownList/>, but they're effectively the same thing, so thanks =]
Ed Woodcock
I'm assuming you are asking about client-side JavaScript, which only cares about the document that the browser sees. It has no idea about the ASP ... and since I'm not as ASP programmer, I can only guess :) It does help to reduce examples as much as possible.
David Dorward
sorry, I always forget that asp controls are generally just html controls with server side methods, I normally only do ASP programming!
Ed Woodcock