I want to have textboxes related to radiobuttons. Therefore each radio button should enable it's textbox and disable the others. However when I set the disabled attribute of textbox to true, it changes the editable attribute too. I tried setting editable attribute true again but it did not work.
This was what I tried:
JS function:
function enable(id)
{
var eleman = document.getElementById(id);
eleman.setAttribute("disabled", false);
eleman.setAttribute("editable", true);
}
XUL elements:
<radio id="pno" label="123" onclick="enable('ad')" />
<textbox id="ad" editable="true" disabled="true" flex="1" emptytext="asd" onkeypress="asd(event)" tooltiptext="" >
This question is related to
javascript
firefox
firefox-addon
xul
Just set the property directly: .
eleman.disabled = false;
just replace 'myselect' with your id
to disable->
document.getElementById("mySelect").disabled = true;
to enable->
document.getElementById("mySelect").disabled = false;
Using method set and remove attribute
function radioButton(o) {_x000D_
_x000D_
var text = document.querySelector("textarea");_x000D_
_x000D_
if (o.value == "on") {_x000D_
text.removeAttribute("disabled", "");_x000D_
text.setAttribute("enabled", "");_x000D_
} else {_x000D_
text.removeAttribute("enabled", "");_x000D_
text.setAttribute("disabled", "");_x000D_
}_x000D_
_x000D_
}
_x000D_
<input type="radio" name="radioButton" value="on" onclick = "radioButton(this)" />Enable_x000D_
<input type="radio" name="radioButton" value="off" onclick = "radioButton(this)" />Disabled<hr/>_x000D_
_x000D_
<textarea disabled ></textarea>
_x000D_
Try doing this instead:
function enable(id)
{
var eleman = document.getElementById(id);
eleman.removeAttribute("disabled");
}
To enable an element you have to remove the disabled attribute. Setting it to false still means it is disabled.
the disabled attributes value is actally not considered.. usually if you have noticed the attribute is set as disabled="disabled" the "disabled" here is not necessary persay.. thus the best thing to do is to remove the attribute.
element.removeAttribute("disabled");
also you could do
element.disabled=false;
Source: Stackoverflow.com