Does anyone know how to get the values from an asp dropdownbox (not just the selected one) using javascript?
1 Answer
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;
}
3 Comments
Ed James
actually, an <asp:DropDownList/>, but they're effectively the same thing, so thanks =]
Quentin
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.
Ed James
sorry, I always forget that asp controls are generally just html controls with server side methods, I normally only do ASP programming!