Link to home
Start Free TrialLog in
Avatar of sitijaafar
sitijaafarFlag for Malaysia

asked on

Delete all the value in the multiple list box

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

Avatar of Anuradha Goli
Anuradha Goli
Flag of Ireland image

ListBox1.Items.Clear()
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

ASKER CERTIFIED SOLUTION
Avatar of Anuradha Goli
Anuradha Goli
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi,

i hope u have only one multiple list box

http://www.somacon.com/p542.php
                              
Avatar of Michel Plungjan
@anuradhay in what language is that statement ListBox1.Items.Clear() ?
Avatar of sitijaafar

ASKER

thanks for the great feedback, finally I can solve it using anuradhay code
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