473,508 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5831
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
8856
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
1
4223
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
2
12814
by: bigrich | last post by:
I'm a beginner to javascript and need help. I've searched the forum but can't piece the answer together. I need to be able to uncheck and disable a checkbox based on the option selected in a...
2
2427
by: kiranmn75 | last post by:
I want to dynamically populate a combo box through javascript. Data is coming from a array. Sometimes data list may contain items in excess of 2000. Explorer takes more than 5 seconds to...
19
9834
by: RedDevilDan | last post by:
I am working on a Memory Footprint Reduction project. I came across an idea to disable all printf statements so that less memory is required. In addition, when there is no single printf statement,...
3
6413
by: Beholder | last post by:
I hope that someone can help me with the following: Short background explenation: I have a shrfepoint page (newform.aspx) in a item list. On this page is a lookup column that displays a lookup...
7
16855
chunk1978
by: chunk1978 | last post by:
hello. so i have 2 select menus which add and remove options from a 3rd select menu... it seems, however, that it's not possible to use different select menus to toggle a 3rd, because when an...
1
2914
by: secndChildhood | last post by:
I hope someone can help with this problem: I have a perl cgi form that has a popup_list. Based on a value that is coming in from a database query, I want to either 1) display the value (from...
3
6264
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.