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

Disabling options in option list only works in IE

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a


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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.