PDA

View Full Version : How to select all options of a ListBox?


shvetak
09-12-2002, 10:22 AM
Hi,

I have a listbox control. I want to to select all its options when a checkbox is clicked. How to do it?

glenngv
09-12-2002, 10:27 AM
objSelect = document.yourformname.yourselectname;
for (var i=0;i<objSelect.options.length;i++){
objSelect.options[i].selected=true;
}

of course in your select tag you should add multiple attribute

<select name="..." multiple>
...
</select>

shvetak
09-12-2002, 10:34 AM
My code is something like this :

function CheckAll()
{

var iCtr;
iCtr = document.SalesP.cmbSales.options.length;
for(var i=0; i<iCtr; i++)
{
document.SalesP.cmbSales.options[i].selected=true;
}
}

And only the last option comes selected.

shvetak
09-12-2002, 10:36 AM
..And the select also has the Multiple attribute set.

glenngv
09-12-2002, 10:36 AM
as i said you should add multiple in the select tag to allow multiple select