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
2009-07-22 14:09:05
actually, an <asp:DropDownList/>, but they're effectively the same thing, so thanks =]
Ed Woodcock
2009-07-22 14:10:29
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
2009-07-22 14:12:36
sorry, I always forget that asp controls are generally just html controls with server side methods, I normally only do ASP programming!
Ed Woodcock
2009-07-22 14:14:14