views:

5229

answers:

4

How can i add "readonly" to a specific <input >? .attr('readonly') does not work.

+2  A: 

.attr('readonly', 'readonly') should do the trick. Your .attr('readonly') only returns the value, it doesn't set one.

ceejayoz
jQuery's attr() works on JavaScript properties, not HTML attributes, even though the names imply otherwise. attr('readonly') is actually operating on the DOM Level 1 HTML property readOnly, which is a boolean, so ‘true’ is more appropriate. However, the string 'readonly' is also a truthy value when automatically converted to a boolean, so the above still works.
bobince
+3  A: 
$('#inputId').attr('readonly', true);
CMS
+2  A: 

I think "disabled" excludes the input from being sent on the POST

Pier
A: 

For enabling readonly:

$("#descrip").attr("readonly","true");

For disabling readonly

$("#descrip").attr("readonly","");

Pradeep