0

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.

Beri
  • 10,277
  • 3
  • 24
  • 47
Salesforce Steps
  • 153
  • 1
  • 11

6 Answers6

2

You should use prop instead of attr:

$('input[id$="txtareaID"]').prop('disabled', true); 

jQuery docs

joews
  • 27,174
  • 10
  • 70
  • 84
2

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?

Community
  • 1
  • 1
Beri
  • 10,277
  • 3
  • 24
  • 47
0

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;
Rakesh_Kumar
  • 1,330
  • 1
  • 12
  • 24
0

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

Community
  • 1
  • 1
Israel Fonseca
  • 915
  • 5
  • 18
0

<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/

Srihari
  • 746
  • 1
  • 6
  • 21
0

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
    }
Salesforce Steps
  • 153
  • 1
  • 11