views:

142

answers:

3

Hi,

I have a normal HTML select dropdown box

<select id="day" name="day">
<option value="0">All</option>
<option value="1">Mon</option>
<option value="2">Tue</option>
<option value="3">Wed</option>
<option value="4">Thu</option>
<option value="5">Fri</option>
</select>

But on occassion I want to make some options not clickable, e.g. the Text faded out slightly if possible, and then nothing to happen if the text/value is selected.

Anyone know how?

I'm writing my page in PHP.

+2  A: 

Simply give the option tag an attribute 'disabled'.

<select>
<option value="1" disabled>1</option>
<option value="2">2</option>
</select>

So in this example, 1 will be faded out and un-selectable but 2 will be selectable.

Matt
Note that this does not work in IE6.
mmattax
ok cheers. Great working in Firefox but now IE. dammit:)
thegunner
I'm using IE7 and it's not working. Anyone know an alternative or how to get around this?
thegunner
This is not valid XTML, if that's what you're declaring your page to be. Use `disabled="disabled"` instead. Browsers will probably render it properly anyway (besides IE apparently and of course), but it may cause problems somewhere.
carillonator
+1  A: 

IE 6 requires javascript to disable an item. There is a bug that prevents it from disabling individual items.

See here for details on how to implement this so that it functions in IE6: http://www.lattimore.id.au/2005/07/01/select-option-disabled-and-the-javascript-solution/

Andy
+1 Oops, didnt see this before I posted the exact same link.
Neil Aitken
OK thanks guys. I'll have a look through this shortly hopefully. It looks like it will be the solution.
thegunner
+1  A: 

There is a javascript solution here

http://www.lattimore.id.au/2005/07/01/select-option-disabled-and-the-javascript-solution/

There is no way to do this in IE without a JS hack sadly.

Neil Aitken