selecting all options in a dropdown

D

debugger

I have a drop down with alot of options say about 6000 cities and
districts. I need to select all options if user selects "All checkbox".
I use "on change" and a for loop to do this, but it takes a lot of time
to select all these options. Is there any faster way to select all
these options?

function selectAll()
{
var element = document.getElementById("location");
var length = document.getElementById("location").length;

for(var i=0; i<length; i++)
{
element.options.selected=true;
}
}
 
L

Lee

debugger said:
I have a drop down with alot of options say about 6000 cities and
districts. I need to select all options if user selects "All checkbox".
I use "on change" and a for loop to do this, but it takes a lot of time
to select all these options. Is there any faster way to select all
these options?

1. 6000 entries is far too many for a drop down.
2. If you need to select all of 6000 entries, just have
a checkbox marked "all". No need to actually select them.
 
D

debugger

thanks for your reply. Well, i need to add few things to my question.
the total is about 6000, but this drop depends on the input from the
other drop down. So, at one time, only about five hundred are in this
drop down. Now, is there any other way of optimizing the above code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top