You are here: irt.org | FAQ | JavaScript | Form | Q1730 [ previous next ]
Try:
<html> <head> <script language="JavaScript"><!-- function removeOptionsByText(selectName, text) { for (var i=selectName.options.length-1; i>=0; i--) { if (selectName.options[i].text == text) { selectName.options[i] = null; } } } function removeOptionsByValue(selectName, value) { for (var i=selectName.options.length-1; i>=0; i--) { if (selectName.options[i].value == value) { selectName.options[i] = null; } } } //--></script> </head> <body> <form> <select name="selectName"> <option value="fine">test <option value="test">leave this alone <option value="okay">test <option value="xyz">test <option value="test">okay <option value="123">test </select> <input type="button" value="remove" onClick="removeOptionsByText(this.form.selectName,'test')"> <input type="button" value="remove" onClick="removeOptionsByValue(this.form.selectName,'test')"> </form> </body> </html>