2

I want to know how to enable a disabled input field.

<input type="text" class="form" value="Text" disabled="">

I've tried to use this code via tampermonkey

var fContrl = document.getElementsByClassName("form");
for (var i = 0; i < fContrl.length; i++)
    fContrl[i].setAttribute("disabled", false);

But it doesn't work

whm11whm
  • 37
  • 1
  • 3

6 Answers6

2

You need to set the property not the attribute

// Disable
fContrl[i].disabled = true;

// Enable
fContrl[i].disabled = false;
Sean
  • 1,444
  • 1
  • 11
  • 21
1

remove the disabled attribute - see demo below:

var fContrl = document.getElementsByClassName("form");
for (var i = 0; i < fContrl.length; i++)
    fContrl[i].removeAttribute("disabled");
<input type="text" class="form" value="Text" disabled="">
kukkuz
  • 41,512
  • 6
  • 59
  • 95
0

Try this way:

var fContrl = document.getElementsByClassName("form");
for (var i = 0; i < fContrl.length; i++)
    fContrl[i].disabled=false;
nacho
  • 5,280
  • 2
  • 25
  • 34
0

Check this link.

You can directly remove the attribute disabled.

fContrl[i].removeAttribute("disabled");
Rahul
  • 18,271
  • 7
  • 41
  • 60
0

Remove disable attribute from your input field.

JavaScript Code

fContrl[i].removeAttribute("disabled");
vivek s vamja
  • 1,001
  • 10
  • 11
0

You can achieve it by changing the line

 fContrl[i].setAttribute("disabled", false);

to

fContrl[i].disabled=false;
CCoder
  • 151
  • 12