0

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.)

Thomas
  • 7,643
  • 14
  • 43
  • 74

2 Answers2

5

Use setAttribute and removeAttribute:

selectElement.options[i].setAttribute("disabled", "disabled");
selectElement.options[i].removeAttribute("disabled");
Gumbo
  • 620,600
  • 104
  • 758
  • 828
3

The DOM object's property is a boolean value, that should be set to true or false:

selectElement.options[i].disabled = false;

Also see Boolean HTML Attributes.

Community
  • 1
  • 1
Marcel Korpel
  • 21,285
  • 5
  • 59
  • 80