By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

how to disable options in an option list?

P: n/a
Does anybody know how to disable only certain options of an option list
by a javascript function? With the following function you can disable a
option list completely:

function disableList()
{
var x=document.getElementById("myOptionList")
x.disabled=true
}

But what if I just want to disable one option, or two - so that this
option cannot be clicked / selected anymore?

By the way: <optgroup label="disabledOption"> is not an option, since I
have to disable / enable the options in real time according to users input.

I've been stuck with this problem for days now, so any help would be
greatly appreciated!
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Fluffy Convict wrote on 05 dec 2004 in comp.lang.javascript:
Does anybody know how to disable only certain options of an option
list by a javascript function? With the following function you can
disable a option list completely:

function disableList()
{
var x=document.getElementById("myOptionList")
x.disabled=true
}

But what if I just want to disable one option, or two - so that this
option cannot be clicked / selected anymore?


disabled, style.display and style.visibility do not work as expected.

You could remove an option dynamically:
<form name="testform">
<select name="testselect" id="testselect">
<option value="first">first option</option>
<option value="second">second option</option>
<option value="third">third option</option>
</select>
</form>

<script type='text/javascript'>
var node = document.getElementById('testselect');

function removeOption(x){
node.removeChild(node.options[x]);
}

removeOption(1)
</script>
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.