Reputation: 183
I want to make Textarea Disable (Grayed out) in my JS Method
function myfun(status){
if(status=='Yes'){
$('input[id$="txtareaID"]').attr('disabled','disabled');
}
The above code is not working for this.
Upvotes: 0
Views: 1579
Reputation: 183
none of the below answers worked. Then I found something amazing trick which solved my problem --- Here it is --- JUST REMOVE "input" word from that line in if block -
WORKED CODE :
function myfun(status){
if(status=='Yes'){
$('[id$="txtareaID"]').attr('disabled','disabled');
}
Previous CODE :
function myfun(status){
if(status=='Yes'){
$('input[id$="txtareaID"]').attr('disabled','disabled');
$('input[id$="txtareaID"]').prop('disabled',true); //Didn't worked either
}
Upvotes: 0
Reputation: 766
<textarea>
is what you should be looking for not the <input>
tag with id = textareaid
.
$('input[id$="txtareaID"]').attr('disabled','disabled');
change the above code to the below one and see the magic by clicking the link at the bottom.
$('textarea[id$="txtareaID"]').attr('disabled','disabled');
http://jsfiddle.net/5s9ge7d6/1/
Upvotes: 0
Reputation: 1083
Your problem is with CSS not JS. As far I can tell your code is working, but there's no way of changing this specific style. You could try workarounds: Change Font Color For Disabled Input
Upvotes: 0
Reputation: 11600
If your selector is correct, than you need only to change attr
to prop
:
function myfun(status){
if(status === 'Yes'){ // more suitable for comparing
$('input[id$="txtareaID"]').prop('disabled',true);
}
}
Related post: Disable/enable an input with jQuery?
Upvotes: 2
Reputation: 30330
You should use prop
instead of attr
:
$('input[id$="txtareaID"]').prop('disabled', true);
Upvotes: 2
Reputation: 1442
Considering textarea as
<textarea id='txt'>Something</textarea>
Using jQuery, you can achieve like this
$("#txt").attr('disabled', true);
Using plain javascript
document.getElementById("txt").disabled=true;
Upvotes: 0