9

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
  • 24,555
  • 57
  • 174
  • 303

3 Answers3

16

Use readonly attribute instead :

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

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

zessx
  • 68,042
  • 28
  • 135
  • 158
5

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
  • 201
  • 3
  • 5
1
document.forms['formName']['inputName'].readOnly = true;
Govind Singh
  • 15,282
  • 14
  • 72
  • 106