Forum Moderators: open
I have the following select menu:
<select name="things" id="things">
<option value="fruit"> - Fruits - </option>
<option value="re">apple</option>
<option value="pe">pear</option>
<option value="color"> - Colours- </option>
<option value="bl">blue</option>
<option value="re">red</option>
</select>
As "fruit" and "color" are category groups, and not actual selectable options, I want to either disable (preferred) and/or change the background color of the category groups (not the categories).
Normally I would add "disabled='disabled'" to the menu, but in this situation I am unable to do that.
I'm wondering if it's possible to write some javascript at the bottom of the page that will do the disabling for me. Something like:
var cats = document.getElementById("things")
cats.options['fruit'].disabled=true;
cats.options['colour'].disabled=true;
This doesn't work.
Am I not doing this right, or is this not even possible?
Thanks
For example:
<select name="things" id="things">
<optgroup label="- Fruits -">
<option value="re">apple</option>
<option value="pe">pear</option>
</optgroup>
<optgroup label="- Colours -">
<option value="bl">blue</option>
<option value="re">red</option>
</optgroup>
</select>
The thing is I'm using zend_framework for this site and you have to use their zend_form module. I can pass it a single array and set some basic "select level" options, like class, but I can't pass it "option level" items. Hence wanting to do this outside of the select itself. I know this is a dirty hack and there must be a better way of doing this in ZF, but I'll be dammed if I can find out how.
Shall I take it that this isn't possible do do with javascript?
Your other option would be to simply use two separate select dropdowns.
disabled="disabled" will not work, as that is not a valid attribute for options. disabled="disabled" will not work, as that is not a valid attribute for options.