Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable a text box without using disabled

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?

like image 980
cdub Avatar asked Jul 18 '14 08:07

cdub


2 Answers

Use readonly attribute instead :

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

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

like image 154
zessx Avatar answered Oct 01 '22 06:10

zessx


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.

like image 36
Ashish Gaikwad Avatar answered Oct 01 '22 08:10

Ashish Gaikwad