473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

What is the best way to empty a list box?

What is the best way to empty a list box, 1, 2 or 3?

1. document.myForm.myListBox.options.length=null;

2. document.myForm.myListBox.options.length=0;

3. for (var i=0; i<document.myForm.myListBox.options.length; i++)
document.myForm.myListBox.options[i]=null;

Nov 3 '06 #1
2 7637

mark4asp wrote:
What is the best way to empty a list box, 1, 2 or 3?

1. document.myForm.myListBox.options.length=null;

2. document.myForm.myListBox.options.length=0;

3. for (var i=0; i<document.myForm.myListBox.options.length; i++)
document.myForm.myListBox.options[i]=null;
#1 doesn't look like it will work.

#2 works.

#3 will only remove half of them - the collection is live. A better
alternative would be:

var sel = document.myForm.myListBox;
while (sel.firstChild){
sel.removeChild(sel.firstChild);
}

#2 wins on simplicity.

--
Rob

Nov 3 '06 #2
ASM
mark4asp a écrit :
What is the best way to empty a list box, 1, 2 or 3?

2. document.myForm.myListBox.options.length=0;
is enough
Nov 3 '06 #3

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

Similar topics

7
by: Chris Connett | last post by:
I was wondering if there were a well known pattern/idiom for breaking a sequence into a list of lists, each n elements long, e.g. -> ,,] This comes up reasonably often in my work, and every...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: John Cho | last post by:
/* This program is a database program that will store video tape names, minutes, year released, and price I want it to be professional so that *YOU* will want to buy it and use it for a video...
25
by: Matthias | last post by:
Hi, I am just reading that book by Scott Meyers. In Item 4 Meyers suggests to always use empty() instead of size() when probing for emptyness of STL containers. His reasoning is that size()...
4
by: Chris | last post by:
Hi, What's the best way to check if two or more textboxes are empty before executing a task? I have the foll which is NOT WORKING If Not (txtDateFrom.Text Is Nothing) And (txtDateTo.Text Is...
16
by: Ajay | last post by:
Hi all, i want to know when i create a class.what all it contains.I know the following things are there by default if i do not declare them by myself.Please tell the other things that are left. ...
1
by: Mose | last post by:
Greetings! I am designing an Access '97 database for my company and have run into an issue as to how best to record the various features for the items we sell. For example a refrigerator can...
1
by: psbasha | last post by:
Hi, Whether we can check the empty list or dict by i"f "conditon or catch this exception by "try" and "catch" blocks. Which will be the best practctice?. In my work I have to play with...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.