sitijaafar
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.
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);
}
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@anuradhay in what language is that statement ListBox1.Items.Clear() ?
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" />