473,668 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

selecting all options in a dropdown

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.getEle mentById("locat ion");
var length = document.getEle mentById("locat ion").length;

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

Jul 23 '05 #1
3 1951
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.

Jul 23 '05 #2
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?

Jul 23 '05 #3
debugger wrote:
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?

You need to think about your architecture: a user isn't going to click
on even a fraction of 500 list entries, particularly in a dropdown,
still less in a multi-select dropdown (which are almost impossible to use).

If you have 6000 locations, then on page 1, offer "all" or
"Europe/Africa/USA, etc.". On page 2, assuming Europe, offer "all" or
"UK, France, Germany, etc.". On page 3, assuming France, offer "all" or
"Paris, Lyons, Strasbourg, etc." This isn't JavaScript, but sometimes
the best code is no code at all :-)

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2286
by: JL | last post by:
Does anyone have any ideas on this please? I don't know how to evaluate the no-blank selections against each other from a form as follows: . I have a form with 6 dropdown fields, each containing a selection of 30 options (the 30 options are the same for each dropdown list). The user needs to select 'one of the 30 options' from each dropdown selection, but each option they select must be unique (no duplicate selections) or it must be...
1
3607
by: jzhang29 | last post by:
I have a JSP page and it contains a dropdown list called Office. What I try to do is: When I select different office from this list, the information of office (address, phone,etc) will be populated in same JSP page. I have a java bean called officeBean that contains all the office information.
4
1982
by: Doslil | last post by:
I have a form which has a subform.In the main form I have only one field (this is a drop down list and has a query attached to it) which selects empno,Name from the EmployeeInformation table. The sub form stores the time sheet data for each employee.When I am able to do the timesheet data entry for the first record.But when I select the second employee from the dropdown list and click on the subform for entering the timesheet data, it...
2
2049
by: ahoodless | last post by:
hi i have a problem that I have tried desperately to tackle but cannot seem to complete. basically i am trying to create a form with three dropdown lists, the tricky part is i want the 3rd drop down box's options to be dependant on the choice made in the 2nd dropdown...and the 2nd dropdown's options to be dependant on the choice made in the 1st dropdown. For example: 1st dropdown product 1
3
3021
by: sewerized | last post by:
Hello all, I'm having a problem with a user preferences form I'm creating. I want to use dynamic dropdown SELECT boxes for this so my page doesn't get cluttered with 100000 links. Since I have 10000 Options embedded in the SELECT tags, I'm using an External JS file to display them. I'm using these same Options for different SELECT tags, so they can be "re-used (or looped)", instead of writing them over and over again.
2
1132
by: peterdorling | last post by:
i have built a table but need one of the options on one of my drop down menu's to require a date to be inputed if you choose it. e.g the options on the dropdown are To Book, Booked, ReBook, Cancel. i need it so that if you choose "booked" it requires you to enter a date before you can leave the record... i am completely stuck on this and all help would be very much appreiciated... thanks
4
3426
by: Panna | last post by:
Hey there I am using phpMyAdmin and MySQL to develop a dbase application. I have a dropdown menu on one of the pages which gets populated automatically with data from a table in the database. The code for this is as follows: $sql3="SELECT ID, UploadDate FROM Telkom"; $result2=mysql_query($sql3); $options="";
3
5861
by: dufnobles via AccessMonster.com | last post by:
I have a form that displays a dropdown box. The options in the drop down vary according to a value queried from a database boolean (Yes/No) field. I would like to do the following: If the boolean value is True, then the dropdown options will be option1 and option2. If the boolean value is False, then the dropdown box will contain: option1, option2 and option3.
2
11277
by: ghjk | last post by:
I have a dropdown box and what i want to do is refresh the page when i select one of the options, but i need to keep that variable that i chose as it effects my sql statements.
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8799
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.