PDA

Click to See Complete Forum and Search --> : .options.remove() only removes some items ?


plenderj
Apr 9th, 2004, 05:05 AM
I have a dropdown, and I want to clear it, but this code only clears some items :confused:


var i = 0; var dropDown = document.search.elements['selProductGroup'];
for (i = 0; i <= dropDown.length; i++) {
dropDown.options.remove(i);
}

plenderj
Apr 9th, 2004, 05:11 AM
And this doesn't make any difference...


for (i = 0; i <= dropDown.length; i++) {
if (! ( dropDown.options[i] == null ) )
dropDown.options.remove(dropDown.options[i].value);
}

TomGibbons
Apr 9th, 2004, 07:32 AM
var i = 0; var dropDown = document.search.elements['selProductGroup'];
dropDown.options.length = 0;
Should clear it?

Acidic
Apr 9th, 2004, 09:31 AM
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:

document.getElementById('selProductGroup').innerHTML = ""


that's if the select is:
<select id="selProductGroup" ... (whatever else)>

TomGibbons
Apr 9th, 2004, 09:47 AM
Works for me (Internet Explorer and FireFox)

Note: Rename to htm/html, apparently we can't upload html files.