how to disable options in an option list?

F

Fluffy Convict

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!
 
E

Evertjan.

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top