Click to See Complete Forum and Search --> : Removing an item from a listbox SELECT - OPTION
Stephen Boston
January 29th, 2003, 03:01 PM
I tried searching for this to no avail.
Does anyone know of a way to remove an item from a html listbox.
We have 2 lists on our page and we are transferring one item from one box to another. This works find. However, we want to be able to remove an item from one ofthe boxes.
My head is flat from pounding it on the wall. :rolleyes:
Has anyone done this feat?
antares686
February 5th, 2003, 05:47 AM
This example is valid for IE. Not sure if there is a difference for Netscape since I am in an IE envrionment.
<html>
<body>
<center>
<p>
<select size="5" name="D1">
<option value="0">All</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select> Group
</p>
<p>
<input type="button" value="Remove Selected" name="B1" OnClick="RemoveOne()">
</p>
<p>
<select size="5" name="D2" multiple>
<option value="0">All</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select> Group
</p>
<p>
<input type="button" value="Remove All Selected" name="B2" OnClick="RemoveSel()">
</p>
</center>
<script Language="JavaScript">
function RemoveOne()
{
D1.remove(D1.selectedIndex)
}
function RemoveSel()
{
while(D2.selectedIndex > -1)
D2.remove(D2.selectedIndex);
}
</script>
</body>
</html>
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.