Solved

Delete all the value in the multiple list box

Posted on 2010-09-22
7
405 Views
Last Modified: 2012-05-10
Hi experts,
Below is my code for delete all the value, but it's not work well because it not delete all the value.
var elSel = document.getElementById("learnCountry1");

	var l=elSel.length;



	

	for (i =0; i < l; i++) {   	  

      elSel.remove(i);	

	  

    }

Open in new window

0
Comment
Question by:sitijaafar
7 Comments
 
LVL 12

Expert Comment

by:Anuradha Goli
ID: 33732736
ListBox1.Items.Clear()
0
 
LVL 22

Expert Comment

by:kadaba
ID: 33732762
you need to remove the options? you can do it like this.

<html>
<head>
<script type="text/javascript">
function clearDropDown(){
	document.getElementById('multi').options.length = 0;
}
</script>
</head>
<body>
<select id="multi" multiple="multiple">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<input type="button" onclick="clearDropDown();" value="clear drop down">
</body>
</html>

Open in new window

0
 
LVL 12

Accepted Solution

by:
Anuradha Goli earned 500 total points
ID: 33732763
var elSel = document.getElementById("learnCountry1");
var l= elSel.options.length;
for(i=elSel.options.length-1;i>=0;i--)
{         
      elSel.remove(i);      
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:Insoftservice
ID: 33732782
hi,

i hope u have only one multiple list box

http://www.somacon.com/p542.php
                              
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33733721
@anuradhay in what language is that statement ListBox1.Items.Clear() ?
0
 

Author Comment

by:sitijaafar
ID: 33740577
thanks for the great feedback, finally I can solve it using anuradhay code
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33741394
Did you try Kadaba's code at all? It is the simplest

<select id="learnCountry1" multiple="multiple">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
<input type="button" onClick="
var elSel = document.getElementById('learnCountry1');
var l= elSel.options.length;
for(i=elSel.options.length-1;i>=0;i--) elSel.remove(i);" value="remove all" />

<input type="button" onClick="document.getElementById('learnCountry1').options.length=0;" value="delete all" />

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now