2

I tried to enable a disabled element on click of a P element.The code below will store the value from the textbox into another textbox which I have appended with the div.later this textbox will be disabled.On mouse over the div an edit and delete will appear.On click of the edit, the textbox within the div must be enabled again.

<div id="ta"></div>
<input type="text" id="tb"><br>
<button onclick="add()">Submit</button><br>    

<script type="text/javascript">

var ta="";
    function add() {
        var newDiv="",newTa="",newP="",newImg="";

        ta=document.getElementById('ta');
    newDiv = document.createElement("div");

    ta.appendChild(newDiv);

    newTa = document.createElement("input");
    newTa.type="text"
        newTa.disabled="true";
        newTa.value=document.getElementById("tb").value;

        newDiv.onmousedown=function(){

        newP.style.visibility="visible";
    newImg.style.visibility="visible";  

        };


        newP=document.createElement("p");

        newP.innerHTML="Edit";
        newP.style.visibility="hidden";
        newP.style.display="inline";
        newP.style.padding="5px";
        newP.onclick=function()
        {
           newTa.disabled="false";//this is not working

        }

Why is it not working?Is there any other way to do this?

NIV
  • 458
  • 4
  • 19

2 Answers2

1

The reason is probably because you are providing "false" as a string. From another answer here:

[...] a non empty string is truthy. So assigning "false" to the disabled property has the same effect of setting it to true.

Try using the proper boolean value instead.

newTa.disabled = false;
BadHorsie
  • 14,135
  • 30
  • 117
  • 191
0
newTa.disabled="true"
newTa.disabled="false"

these two should be without ""

newTa.disabled=true
newTa.disabled=false

otherwise you could do it like this:

var x = document.getElementById("mySelect").disabled;

https://www.w3schools.com/jsref/prop_select_disabled.asp

Tibix
  • 400
  • 3
  • 12