Make input text disabled/readonly in IE9 and below using javascript/jQuery -
anyone have idea how this?
i have tried javascript below didn't work.
element.readonly="true"; element.readonly="readonly"; element.disabled="disabled";
tried below jquery has not worked either.
$("#id").attr("disabled","disabled"); $("#id").attr("disabled",true); $("#id").attr("readonly",true); $("#id").attr("readonly","readonly");
am doing wrong or there way achieve ie9 , below?
thanks
if setting attribute value on element, need use string equal attribute setting. example, if setting disabled
attribute, should set equal "disabled"
.
html
<input type="text" disabled="disabled" />
javascript
$("#id").attr("disabled", "disabled");
if setting property value, need use boolean value: true
or false
. properties set in javascript:
javascript
element.disabled = true;
in first example above, setting javascript properties strings, instead of boolean values. why didn't work.
here possibilities work you:
//any of following work element.readonly = true; //it readonly, not readonly element.disabled = true; $("#id").attr("disabled", "disabled"); $("#id").attr("readonly", "readonly"); //additionally, can use jquery's prop() method, don't recommend it. $("#id").prop("disabled", true); $("#id").prop("readonly", true); $("#id").prop("readonly", true); //jquery bridge gap here, , fix you.
it's important understand disabled
, readonly
serve different functions:
disabled
means can't interact element @ all. elementsdisabled
immutable, meaning value can't modified. omitted form submissions.readonly
means can't change value of element.
Comments
Post a Comment