Deselect listbox item in javascript: Deselect or unselct item in JavaScript by simply assigning false property to selected option , look at the example –
Deselect listbox item using javascript
<script>
function DeselectListBox()
{
var ListBoxObject=document.getElementById("fruits")
for (var i = 0;i < ListBoxObject.length; i++)
{
if (ListBoxObject.options[i].selected )
{
ListBoxObject.options[i].selected = false
}
}
}
</script>
<select name="fruits" id="fruits" multiple>
<option value="Apple">Apple</option>
<option value="Apricot">Apricot</option>
<option value="Asparagus">Asparagus</option>
<option value="Fig">Fig</option>
<option value="Avocado">Avocado</option>
<option value="Banana">Banana</option>
<option value="Clementine">Clementine</option>
<option value="Honeydew melon">Honeydew melon</option>
</select>
<button onclick="javascript:DeselectListBox();">Deselect List Box</button>
No comments:
Post a Comment