Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.setAttribute("disabled", false); changes editable attribute to false

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="" > 
like image 290
Ghokun Avatar asked Sep 23 '11 09:09

Ghokun


People also ask

How to set disabled attribute in JavaScript to false?

To set the disabled attribute, select the element and call the setAttribute() method on it, passing it disabled as the first parameter, e.g. button. setAttribute('disabled', '') . The setAttribute method will add the disabled attribute to the element.

How do you make a field Disabled in HTML?

The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable. Tip: Disabled <input> elements in a form will not be submitted!

How do I disable a button?

To disable a button using only JavaScript you need to set its disabled property to false . For example: element. disabled = true . And to enable a button we would do the opposite by setting the disabled JavaScript property to false .

What is setAttribute in JavaScript?

setAttribute() Sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified name and value.


1 Answers

A disabled element is, (self-explaining) disabled and thereby logically not editable, so:

set the disabled attribute [...] changes the editable attribute too

Is an intended and well-defined behaviour.

The real problem here seems to be you're trying to set disabled to false via setAttribute() which doesn't do what you're expecting. an element is disabled if the disabled-attribute is set, independent of it's value (so, disabled="true", disabled="disabled" and disabled="false" all do the same: the element gets disabled). you should instead remove the complete attribute:

element.removeAttribute("disabled"); 

or set that property directly:

element.disabled = false; 
like image 105
oezi Avatar answered Sep 18 '22 16:09

oezi