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
  • 8,357
  • 15
  • 45
  • 81

2 Answers2

5

Use setAttribute and removeAttribute:

selectElement.options[i].setAttribute("disabled", "disabled");
selectElement.options[i].removeAttribute("disabled");
Gumbo
  • 643,351
  • 109
  • 780
  • 844
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,536
  • 6
  • 60
  • 80