Link to home
Start Free TrialLog in
Avatar of Phoebe_Yi
Phoebe_Yi

asked on

Delete an option from Combo box

May I know how to delete an option from combo box? for e.g, in my combo box there are 5 options:

red
blue
black
yellow
white

if user click an radio button, I need to remove black from the combo box, may I know how to do tt?
Avatar of lil_puffball
lil_puffball
Flag of Canada image

Here's a quick example:

<form>

<select>
<option>red
<option>blue
<option>green
<option>black
</select>

<input type=radio name=clrs onclick="remove(0);">Red
<input type=radio name=clrs onclick="remove(1);">Blue
<input type=radio name=clrs onclick="remove(2);">Green
<input type=radio name=clrs onclick="remove(3);">Black

</form>

<script>
function remove(n){
  var sel=document.forms[0].elements[0];
  sel.options[n]=null;
}
</script>
ASKER CERTIFIED SOLUTION
Avatar of lil_puffball
lil_puffball
Flag of Canada 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