70204

Question:
I have a list with enabled and disabled option. I do know how to disable an option element but what I don't know how to enable it again.
<select size="1" id="x">
<option value="47" disabled="disabled">Value 47</option>
...
selectElement.options[i].disabled = 'disabled';
// ... how to enable?
It should be done with Plain Javascript and no JavaScript Framework. (I wish I could use Prototype or a similar framework but I cannot introduce one of them.)
Answer1:Use <a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-F68F082" rel="nofollow">setAttribute
</a> and <a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-6D6AC0F9" rel="nofollow">removeAttribute
</a>:
selectElement.options[i].setAttribute("disabled", "disabled");
selectElement.options[i].removeAttribute("disabled");
Answer2:The DOM object's <em>property</em> is a boolean value, that should be set to true
or false
:
selectElement.options[i].disabled = false;
Also see <a href="https://stackoverflow.com/questions/706384/boolean-html-attributes" rel="nofollow">Boolean HTML Attributes</a>.