Solved

Delete an option from Combo box

Posted on 2004-04-12
2
292 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
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

809 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