Hello I am trying to get the options from a html select el开发者_StackOverflow社区ement. The logic I am using is working in firefox, but it isn't working in IE. It gives me the length of the options array or the number of options but it isn't giving me the values of options. How do I troubleshoot this issue??
var SelectId= 'select_1'; //id of the html select element
options = document.getElementById(SelectId).options;
alert(options.length);
for(var o=0;o< options.length;o++)
{alert(options[o].value);}
The following code should put the values into a "vals" array.
var sel = document.getElementById('select_1');
var vals = [];
for (var i = 0; i < sel.children.length; ++i) {
var child = sel.children[i];
if (child.tagName == 'OPTION') vals.push(child.value);
}
// vals now contains the values
精彩评论