473,396 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Disabling options in option list only works in IE

I have found a workaround to disable certain options in an option list:

var p = document.forms[0].elements['myOptionList'];
p.selectedIndex=-1;

This works perfectly in IE - the selectedIndex becomes unclickable. It
does, however, not work in FireFox. Does any body have clue why not?

Any help would be greatly appreciated :)
Jul 23 '05 #1
4 1856
Fluffy Convict wrote:
I have found a workaround to disable certain options in an option list:

var p = document.forms[0].elements['myOptionList'];
p.selectedIndex=-1;

This works perfectly in IE - the selectedIndex becomes unclickable.
Not for me.
does, however, not work in FireFox. Does any body have clue why not?


It does not disable anything. It just moves the selected option to the
one before 0, both Firefix and IE display a blank option (a reasonable
outcome I reckon) but all options are still selectable, nothing has
been disabled.

Play code follows:

<html>
<head>
<title>Option play</title>
<script type="text/javascript">
function tryIt() {
var p = document.forms[0].elements['myOptionList'];
p.selectedIndex=-1;
}
</script></head><body>
<form action="">
<select name="myOptionList">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
<input type="button" value="Click me" onclick="tryIt();">
</form>
</body>
</html>
--
Rob
Jul 23 '05 #2


My apologies if this double (triple?) -posted. googlegroups2 beta is the
worst. This is just an approximation: lack of event handlers for MSIE
Option objects makes workarounds problemmatic.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>untitled</title>
<style type="text/css">

body {
font-size: 90%;
}
select {
behavior: url(dselect.htc);
font: normal 80% arial;
color: #000;
background: #f6f6ff;
}

</style>
</head>
<body>
<form>
<select name="s1">
<option value="" selected="selected">&rarr; choose &larr;</option>
<option value=""></option>
<option value="alpha" disabled="disabled">• Alpha</option>
<option value="bravo">• Bravo</option>
<option value="charlie">• Charlie</option>
<option value="delta" disabled="disabled">• Delta</option>
<option value="echo">• Echo</option>
</select>
<select name="s2">
<option value="">&rarr; choose &larr;</option>
<option value=""></option>
<option value="foxtrot">• Foxtrot</option>
<option value="golf">• Golf</option>
<option value="hotel">• Hotel</option>
<option value="india" disabled="disabled">• India</option>
<option value="juliet" disabled="disabled">• Juliet</option>
</select>
</form>
</body>
</html>

[dselect.htc]

<PUBLIC:COMPONENT>
<PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="select_init()" />
<PUBLIC:ATTACH EVENT="onchange" ONEVENT="select_onchange()" />
<SCRIPT>

function select_init()
{
var o = 0,
opt,
opts = this.getElementsByTagName('option');
while (opt = opts.item(o))
{
if (opt.disabled)
opt.style.color = '#888';
if (opt.defaultSelected)
this.defaultIndex = o;
o++;
}
}

function select_onchange()
{
var i = this.selectedIndex;
if (this.options[i].disabled)
this.selectedIndex = this.defaultIndex || 0;
}

</SCRIPT>
</PUBLIC:COMPONENT>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
On Tue, 07 Dec 2004 19:14:03 GMT, Rob B <fe******@hotmail.com> wrote:
My apologies if this double (triple?) -posted. googlegroups2 beta is the
worst.


The thing I'm most annoyed about is that old links to the archived
messages no longer work. Anyway, if you have a proper news reader
(preferably not OE :P), you could always apply for an account at
<URL:http://www.individual.net/>. It's free.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
Michael Winter wrote:
The thing I'm most annoyed about is that old links to the archived
messages no longer work. Anyway, if you have a proper news reader
(preferably not OE :P), you could always apply for an account at
<URL:http://www.individual.net/>. It's free.


Cheers for that (free == my.favorite.word). Looking into it.

Rob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Hal Vaughan | last post by:
I have a sample script from a book ("Beginning JavaScript" by Paul Wilton) that removes or adds a choice to a <SELECT> element. The <FORM> is form1 and the <SELECT> is theDay. The example uses...
9
by: netclectic | last post by:
I'm dynamically adding options to a select list in javascript and i need to be able to set the height of the option, but setting style.height has not effect, I also tried style.pixelHeight but no...
12
by: Nalaka | last post by:
Hi, I suddenly started getting a lot of errors from html validation (some CSS) so I followed the following instructions to disable it. If you'd rather not have these types of HTML validation...
9
by: Paul Keegstra | last post by:
Hi, I am currently working on an asp.net 2.0 web site that is a replacement of a classic asp web site. The current web site uses a Commerce Server 2002 database for storing user information. ...
2
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...
3
by: TKapler | last post by:
i got this simmple function, It stays on onChange on select and on change it hides all objects with ID equal to select name plus the optionvalue. It works perfectly in Opera and FF, but IE crashes...
3
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...
11
by: Tim Streater | last post by:
Am I right in thinking that while I can disable a select, I can't disable the <option>s within the select? I think this is the case but would like to be sure. Thanks, -- tim
7
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.