Re: Clear all optgroups and options from a select list




RobG wrote:
darwinist wrote:

Brian D wrote:
I have a multiple select list that is created dynamically based on a
previous selection on an asp page. The first thing I do is to clear
the curent option list by

document.form1.itemcross.length = 0;

The only problem is that it leaves the optgroups. How do I also get
rid of the optgroups?

Thanks
BrianD

You need an id for the object or a reference to it:

The OP has already indicated how he's doing that, and may be using
either an ID or a NAME attribute.


<script>

Please don't recommend using invalid HTML. Do it in your own library
if you wish, but don't encourage it here.


// delete an object by reference
function del(element){element.parentNode.removeChild(element);}

The OP is attempting to remove the child nodes, not the element itself.

Isn't an optgroup an element that you can remove like any other?
http://www.w3schools.com/tags/tag_optgroup.asp


--
Rob

.



Relevant Pages