Solved

Delete an option from Combo box

Posted on 2004-04-12
2
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10810125
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
ID: 10810149
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

734 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