6

Is there a simple Javascript or JQuery way to make a textbox disabled WITHOUT using the attribute disabled?

We are using Handlebar.js and when a disabled field is found it skips the field when its serialized so we can't use the disabled attribute. Is there a way to make the textbox uneditable still? Perhaps with a focus or blur?

cdub
  • 22,735
  • 52
  • 164
  • 287

3 Answers3

14

Use readonly attribute instead :

$('#textBox').prop('readonly', true);

Use .attr() instead of .prop() if you're using jQuery < 1.9

zessx
  • 66,778
  • 28
  • 130
  • 153
2

directly add "readonly" attribute to the input element like this

Name: <input type="text" value="editing me is disabled" readonly>

It works like charm. No need of using jquery for that.

Ashish Gaikwad
  • 171
  • 1
  • 5
1
document.forms['formName']['inputName'].readOnly = true;
Govind Singh
  • 14,768
  • 13
  • 67
  • 100