Bob
Bob

Reputation: 11

what is the code to enable HTML input box that has been disabled, using javascript only, not jQuery

document.getElementById(boxname ).disabled=false;

doesn't work.

document.getElementById(boxname ).removeAtribute('disabled');

doesn't work.

What will work? javascript only no jQuery etc. please.

<input id="boxname" />

Upvotes: 1

Views: 107

Answers (3)

abhisekp
abhisekp

Reputation: 5672

Actually Sometimes works when code placed in a particular place in the script See my rotation code: http://jsfiddle.net/crownabhisek/kPybv/42/

Here, in the script section, in the rotate() function, when the document.getElementById("rotation").removeAttribute("disabled"); is written in the 1st place where I've inserted a comment, it works. But in the 2nd place where I've inserted a comment it doesn't work.

No clue why.

But the code to disable is indeed document.getElementById("rotation").removeAttribute("disabled"); and it should actually work.

Upvotes: 0

Sushanth --
Sushanth --

Reputation: 55740

document.getElementById(boxname)

supposed to be

document.getElementById('boxname')

You are missing the Quotes in there. Id should be passed as a string.

OR

var boxname = 'boxname';

// Now you can pass in without any Quotes

 document.getElementById(boxname)

Upvotes: 2

Joseph Silber
Joseph Silber

Reputation: 219920

Setting the disabled property to false is the way to go, you just have to first select the element. To do that, pass an ID string to getElementById:

document.getElementById('boxname').disabled = false;

Upvotes: 3

Related Questions