?
Solved

Delete all the value in the multiple list box

Posted on 2010-09-22
7
Medium Priority
?
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

777 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