I have the following in the page
<select name="val" size="1" >
<option value="A">Apple</option>
<option value="C">Cars</option>
<option value="H">Honda</option>
<option value="F">Fiat</option>
<option value="I">Indigo</option>
</select>
I would like to remove certain values from my select if certain conditions are true.
E.g
if(frm.product.value=="F"){
// remove Apple and Cars from the select list
}
How can I do this using javascript
Removing an option
If you are using JQuery, it goes as follows:
Give an ID to your SELECT
The best answer is this
Because your visitor can also add custom options as he want and delete them without need any info about his options . This code is the most responsive delete code that you can write as your selected delete..
enjoy it:))))
with pure javascript
not tested with IE (if someone can confirm it...)
You may use:
Update: If you modify your select box a bit to this
the non-jQuery solution would be this
Put it inside your if-case. What it does is just to check for the current object within the document and replace it with nothing. You'll have too loop through the list first, I am guessing you are already doing that since you have that if.