471,119 Members | 1,136 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

how to disable options in an option list?

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
1 5665
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.

Similar topics

1 post views Thread by hortoristic | last post: by
2 posts views Thread by kiranmn75 | last post: by
19 posts views Thread by RedDevilDan | last post: by
1 post views Thread by secndChildhood | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.