_JHL_
asked on
How can clear all options and optgroup of select?
Hi,
I want to clear a Select elements. I haven´t any proble with the options, but with the Optgroup I have a problem.
When the page loads, the select list fills with some values, that are grouped. The I have a button that change those values with it´s key, and then I refill the select with the new values. Here the Optgroup is repeated.... I don´t want to replace the select wqith a new elemnt, because I create this select at first time from a class with some characteristics and functions assigned.
So, how I can clear all the optgroup??
Thanks
Hugo
I want to clear a Select elements. I haven´t any proble with the options, but with the Optgroup I have a problem.
When the page loads, the select list fills with some values, that are grouped. The I have a button that change those values with it´s key, and then I refill the select with the new values. Here the Optgroup is repeated.... I don´t want to replace the select wqith a new elemnt, because I create this select at first time from a class with some characteristics and functions assigned.
So, how I can clear all the optgroup??
Thanks
Hugo
Hi
Hope this helps
To remove all:
function removeAllOptions(selectbox )
{
var i;
for(i=selectbox.options.le ngth-1;i>= 0;i--)
{
selectbox.remove(i);
}
}
///////////Or ///////////
endSelect = document.getElementById('e ndSelect') ;
/* Clear out the current options */
for (i = 0; i < endSelect.options.length; i++) {
endSelect.options[i] = null;
}
By Nab
Hope this helps
To remove all:
function removeAllOptions(selectbox
{
var i;
for(i=selectbox.options.le
{
selectbox.remove(i);
}
}
///////////Or ///////////
endSelect = document.getElementById('e
/* Clear out the current options */
for (i = 0; i < endSelect.options.length; i++) {
endSelect.options[i] = null;
}
By Nab
Hi
To remove only selected options
function removeOptions(selectbox)
{
var i;
for(i=selectbox.options.le ngth-1;i>= 0;i--)
{
if(selectbox.options[i].se lected)
selectbox.remove(i);
}
}
By Nab
To remove only selected options
function removeOptions(selectbox)
{
var i;
for(i=selectbox.options.le
{
if(selectbox.options[i].se
selectbox.remove(i);
}
}
By Nab
ASKER
nasbol....
Thanks, I actually use that function to clear the options, but my problem comes with the optgroup, they don´t deleted.... I want to clear all inclusive the optgroup
Thanks...
Thanks, I actually use that function to clear the options, but my problem comes with the optgroup, they don´t deleted.... I want to clear all inclusive the optgroup
Thanks...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't get what you mean by "optgroup" :-(
If it is what I said, then:
select.options.length = 0 ;
will clear them