Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable a disabled text field?

I wanna know how do I enable a disabled form text field on submit. Also I wanna make sure if user goes back to form or click reset field will show again as disabled.

I tried to use

document.pizza.field07.disabled = false ;

It does disables the field, by clicking reset or hitting back button still keeps it enable.

Please guide.

like image 280
Hassan Z Avatar asked Dec 13 '11 04:12

Hassan Z


People also ask

How do I enable a disabled field?

The ng-disabled directive sets the disabled attribute of a form field (input, select, or textarea). The form field will be disabled if the expression inside the ng-disabled attribute returns true. The ng-disabled directive is necessary to be able to shift the value between true and false .

How do I enable and disable a textbox in HTML?

We can easily disable input box(textbox,textarea) using disable attribute to “disabled”. $('elementname'). attr('disabled','disabled'); To enable disabled element we need to remove “disabled” attribute from this element.

How do I enable input field on click?

To enable it again add $("#FullName"). removeAttr('disabled'); in the onclick handler of another button or field.


3 Answers

To access this element in a more standard way, use document.getElementById with setAttribute

document.getElementById("field07").setAttribute("disabled", false);

EDIT

Based on your comment, it looks like field07 is a name, not an id. As such, this should be what you want:

var allfield7s = document.getElementsByName("field07");
for (var i = 0; i < allfield7s.length; i++)
    allfield7s[i].setAttribute("disabled", false);
like image 112
Adam Rackis Avatar answered Sep 24 '22 02:09

Adam Rackis


That is the only working solution for Me:

var allfield7s = document.getElementsByName("field07");
for (var i = 0; i < allfield7s.length; i++)
    allfield7s[i].removeAttribute("disabled");
like image 27
zajc3w Avatar answered Sep 23 '22 02:09

zajc3w


You can enable a disabled html control with the following JavaScript code.

document.getElementById('elementId').removeAttribute('disabled');

like image 8
Bins Jose Avatar answered Sep 25 '22 02:09

Bins Jose