SAN CAZIANO wrote:
how can clear an html SELECT and next insert in it all the
elements of an array ()I try this but seems doesn't works.
function
ComboAddArrayValueWithLabel(combo,ArrayLabel,Array Value){combo.options.length
= 0;for (i=0; i<ArrayLabel.length; i++)
combo.options[combo.options.length] = new
Option(ArrayLabel[i],ArrayValue[i]);}
It's usually best to provide a complete example that demonstrates
the problem you are experiencing, and a complete explanation of
the behavior you are experiencing, and how it differs from the
behavior you are expecting (<url:
http://www.physci.org/codes/sscce.jsp />). For example:
<form name="myForm">
<select name="mySelect">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
<input type="button" name="myTest"
value="Test"
onclick="test(this.form.elements['mySelect'], labels,
values);">
</form>
<script type="text/javascript">
var labels = [
'four', 'five', 'six'
];
var values = [
4, 5, 6
];
function test(combo, ArrayLabel, ArrayValue) {
combo.options.length = 0;
for (var i = 0; i < ArrayLabel.length; ++i) {
combo.options[combo.options.length] =
new Option(ArrayLabel[i], ArrayValue[i]);
}
// combo.options[0].selected = true;
}
</script>
Works as shown in IE 6.0.2800, Firefox 1.0, Opera 7.54 and
Netscape 4.78 (if you uncomment the last line of -test-).
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq