Friday, May 18, 2012

add "readonly' to <input > (jQuery)


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



Source: Tips4all

5 comments:

  1. $('#inputId').attr('readonly', true);

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

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

    ReplyDelete
  4. You can disable the readonly by using the .removeAttr;

    $('#descrip').removeAttr('readonly');

    ReplyDelete
  5. For enabling readonly:

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


    For disabling readonly

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

    ReplyDelete