Basically, I want to disable all SELECT elements that have zero OPTIONS elements or OPTION elements where the value is empty.
For instance, the following two examples would be disabled:
- <select>
- </select>
- <select>
- <option value=''></option>
- </select>
These would not be disabled:
- <select>
- <option value=''></option>
- <option value='10'>10 Miles</option>
- <option value='20'>20 Miles</option>
- </select>
- <select>
- <option value='1'>10 Miles</option>
- </select>
I tried using the following jQuery (using Richfaces), but I can't get it to work:
- <rich:jQuery selector="select" query="(':not(:has(option:not([value=])))').attr('disabled', true)" />
This is the resulting javascript:
- <script type="text/javascript">
- //<![CDATA[
- {
- var selector = "select";
- try {
- selector = eval("select");
- } catch (e) {}
- jQuery(selector).(':not(:has(option:not([value=])))').attr('disabled', true);
- }
- //]]>
- </script>