Connecting Tech Pros Worldwide Help | Site Map

Disabling options in option list only works in IE

Fluffy Convict
Guest
 
Posts: n/a
#1: Jul 23 '05
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 :)
RobG
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Disabling options in option list only works in IE


Fluffy Convict wrote:[color=blue]
> 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.[/color]

Not for me.
[color=blue]
> does, however, not work in FireFox. Does any body have clue why not?[/color]

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
Rob B
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Disabling options in option list only works in IE




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!
Michael Winter
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Disabling options in option list only works in IE


On Tue, 07 Dec 2004 19:14:03 GMT, Rob B <ferndoc9@hotmail.com> wrote:
[color=blue]
> My apologies if this double (triple?) -posted. googlegroups2 beta is the
> worst.[/color]

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.
Rob B
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Disabling options in option list only works in IE


Michael Winter wrote:
[color=blue]
> 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.[/color]

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!
Closed Thread


Similar JavaScript / Ajax / DHTML bytes