function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Soumya sri yaravaSoumya sri yarava 

Disable the command button in salesforce , enable and disable in Repeat function

Hi, iam working with wrapper class, if i dnt select any checkboxes, the command button should be in disable mode.
1)if selected any one  checkbox, then the command button should have to enable mode.

how to acheive this function using in repeat functionality and wrapper class, please help out.
  can any one explain how to do in javascript, pleaase thanks in advance...!
public class test3{
 public list<string>listSelectedNames{get;set;}
 public list<Wrapperclass>wraplist{get;set;}
 public list<Wrapperclass> containslistcheck{get;set;}

  
  public test3(){
 listSelectedNames = new list<string>();
containslistcheck  = new list<Wrapperclass>(); 
 
 wraplist = new list<Wrapperclass>();
   Wrapperclass   wf = new Wrapperclass();
                  wf.selected=false;
                  wf.name ='Samsung';
                   wf.state='AndhraPradesh';
                 
    Wrapperclass   wf1 = new Wrapperclass();
                  wf1.selected=false;
                  wf1.name ='Oneplus';
                   wf1.state='Telangana';
                                  
          wraplist.add(wf);
          wraplist.add(wf1);
         
         
 }
 
 
   public void duplicatecheck(){
    listSelectedNames.clear();
   
    
    for(wrapperclass wrap: wraplist){
        if(wrap.selected == true){
           
            listSelectedNames.add(wrap.Name);
           
         }  
    }
    
    system.debug(listSelectedNames);
}


 //wrapper classs
    public class Wrapperclass{
       public boolean selected{get;set;}
       public string Name{get;set;}
        public string state{get;set;}
    }
  
  
}



Visualforce page:;

 
<apex:page controller="test3"  id="pg">
   <apex:form id="fm">
  
  <script>
  
      Disablebtn();
    function Disablebtn(){
    //alert();
    
     //document.getElementById("pg:fm:pb:btn").setAttribute("disabled","disabled");
     //document.getElementById("pg:fm:pb:btn").disabled = disabled ;
     //document.getElementById("pg:fm:pb:btn").disabled = true;
    
     }
  
  </script>     
      
      
      
   <apex:pageBlock id="pb">
      <apex:pageblockTable value="{!wraplist}"  var="a" id="pbt">
       <apex:column ><apex:inputCheckbox value="{!a.selected}"  id="sampletest"/>{!a.name}</apex:column>
        <apex:column >{!a.state}</apex:column>
       </apex:pageblockTable>
    <apex:commandButton value="OrderSelected"  reRender="one,two" action="{!duplicatecheck}"  id="btn"/>
       <apex:outputLabel id="two">{!listSelectedNames}</apex:outputLabel>
    </apex:pageBlock>
   </apex:form>
</apex:page>


thanks in advance
soumya sree
ShirishaShirisha (Salesforce Developers) 
Hi Sowmya,

Greetings!

Please refer the below thread to know how to do it in Javscript by using CSS and also with the Visualforce as well.

https://salesforce.stackexchange.com/questions/142722/hide-show-button-on-visualforce-page

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri