Solved

Delete an option from Combo box

Posted on 2004-04-12
2
290 Views
Last Modified: 2008-03-10
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?
0
Comment
Question by:Phoebe_Yi
  • 2
2 Comments
 
LVL 12

Expert Comment

by:lil_puffball
Comment Utility
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>
0
 
LVL 12

Accepted Solution

by:
lil_puffball earned 100 total points
Comment Utility
Here's a better one:

<form>

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

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

</form>

<script>
function remove(n,rad){
  var sel=document.forms[0].elements[0];
  sel.options[n]=null;
  rad.disabled=true;
  for(i=n*1+1;i<document.forms[0].clrs.length;i++){
    document.forms[0].clrs[i].value--;
  }
}
</script>
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now