[thelist] Disabling & re-enabling options

Chris Blessing webguy at mail.rit.edu
Fri Sep 27 14:37:01 CDT 2002


Fernando-

You want to remove the option from the list?  If so, use this:

<script language="JavaScript1.1">
	function deleteOption(selectBox, optionIndex){
		// pass in document.form.select and the index of the
		// option to delete

		selectBox.options[optionIndex] = null;
	}
</script>

<!-- simple test form -->
<form name="testForm">
	Click on an option to delete it from the select box:
	<br>
	<select name="selectBox"
	onChange="deleteOption(this, this.selectedIndex);">

	<!-- note how we passed in 'this' (the select box) and
	     the selectedIndex so that it deletes the selected
           option appropriately -->

		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
	</select>
</form>

(note: only works with JS 1.1+ browsers)

If you need any help modifying it for other uses, just ask. HTH!

Chris Blessing
webguy at mail.rit.edu
http://www.330i.net

> Thanks James, but it seems I was not clear enough.
>
> What I'm trying to disable is an individual option, not the whole select
> element. By 'disabled' I mean 'not selectable' (if that word
> exists), so it
> doesn't matter wether the option is greyed out, or if it is simply absent
> from the menu.
>
> Regards,
>
> Fernando Gomez



More information about the thelist mailing list