I have a dropdown, and I want to clear it, but this code only clears some items :confused:
Code:var i = 0; var dropDown = document.search.elements['selProductGroup'];
for (i = 0; i <= dropDown.length; i++) {
dropDown.options.remove(i);
}
Printable View
I have a dropdown, and I want to clear it, but this code only clears some items :confused:
Code:var i = 0; var dropDown = document.search.elements['selProductGroup'];
for (i = 0; i <= dropDown.length; i++) {
dropDown.options.remove(i);
}
And this doesn't make any difference...
Code:for (i = 0; i <= dropDown.length; i++) {
if (! ( dropDown.options[i] == null ) )
dropDown.options.remove(dropDown.options[i].value);
}
Should clear it?Code:var i = 0; var dropDown = document.search.elements['selProductGroup'];
dropDown.options.length = 0;
I don't think you can set the length equal to zero, length is read only I think.
also
if (! ( dropDown.options[i] == null ) )
should maybe be:
if (dropDown.options[i] != null )
or maybe that doesn't matter.
if this is a dropdown as in a <select>
then why not:
that's if the select is:Code:document.getElementById('selProductGroup').innerHTML = ""
<select id="selProductGroup" ... (whatever else)>
Works for me (Internet Explorer and FireFox)
Note: Rename to htm/html, apparently we can't upload html files.