Solved

Delete all the value in the multiple list box

Posted on 2010-09-22
7
404 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
Comment Utility
ListBox1.Items.Clear()
0
 
LVL 22

Expert Comment

by:kadaba
Comment Utility
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
Comment Utility
var elSel = document.getElementById("learnCountry1");
var l= elSel.options.length;
for(i=elSel.options.length-1;i>=0;i--)
{         
      elSel.remove(i);      
}
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 15

Expert Comment

by:Insoftservice
Comment Utility
hi,

i hope u have only one multiple list box

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

Expert Comment

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

Author Comment

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

Expert Comment

by:Michel Plungjan
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

772 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

9 Experts available now in Live!

Get 1:1 Help Now