Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delete an option from Combo box

Posted on 2004-04-12
2
Medium Priority
?
301 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 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

926 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