Solved

Delete all the value in the multiple list box

Posted on 2010-09-22
7
408 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 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
null, truthy, falsey confusion 25 43
Glitching Slide Show 19 39
web page freezes after ajax post 7 98
custom drop down menu with dependant results 9 14
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

732 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