1

My web page has a set of input fields that are rarely used, I have to tab through each one of 50 input fields. I want to toggle the input field "disabled" attribute off on a mouse click on the individual field. The code below works. But I want to change #M1 to input child of the div.

<div onclick = "$('#M1').removeAttr('disabled')">">
<input type = "text" disabled id = "M1" />
</div>
verlager
  • 794
  • 5
  • 25
  • 43
  • Possible duplicate of [javascript remove "disabled" attribute to html input](https://stackoverflow.com/questions/11719961/javascript-remove-disabled-attribute-to-html-input) – Heretic Monkey Apr 04 '18 at 15:36

3 Answers3

1
<input type = "text" id = "M1" 
 onclick ="document.querySelector('#M1').disabled = true;" />

This is the right way to do it.. Please try this

PANKAJ NAROLA
  • 164
  • 1
  • 10
0

It won't work because the input is disabled and won't trigger the click event

try like this :

<div onclick = "document.querySelector('#M1').disabled = false;">
    <input type = "text" disabled id = "M1" />
</div>
Coskun Ozogul
  • 2,389
  • 1
  • 20
  • 32
0

You cannot trigger click event of a disabled element. Try to wrap input by a div. Something like this.

<div onclick="$('#input_id').removeAttr('disabled')">
    <input id="input_id" disabled/>
</div>

JSFiddle : https://jsfiddle.net/etv8h468/16/