verlager
verlager

Reputation: 876

need to add "child of div" to change disabled input

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>

Upvotes: 1

Views: 238

Answers (3)

PANKAJ NAROLA
PANKAJ NAROLA

Reputation: 164

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

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

Upvotes: 1

Srivin Prabhash
Srivin Prabhash

Reputation: 16

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/

Upvotes: 0

Coskun Ozogul
Coskun Ozogul

Reputation: 2469

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>

Upvotes: 0

Related Questions