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
lakshmi25lakshmi25 

how to disable checkbox field checkbox

if i check one checkbox in checkbox field how to disable another checkbox field checkbox? i wrote this code but not working

please corect it.

 

<script>
  function disable(Id1,Id2)
   {
 var  x =document.getElementById("Id1");
 var  y = document.getElementById("Id2");
  for ( var i=0; i <x.length; i++){
  if (x[i].checked =true)
{
  y[i].disabled ='true';
}  
  }
   
   }
   </script>

 

 <apex:inputCheckbox value="{!s.absent__c}" id="ch" onclick="disable('{!$Component.ch}','{!$Component.ch1}');" >

 

 <apex:inputCheckbox value="{!s.present__c}" id="ch1" onclick="disable('{!$Component.ch1}','{!$Component.ch}');" >

 

 if check present field one of checkbox  want to disable beside absent field checkbox

MagulanDuraipandianMagulanDuraipandian

Sample code:

 

<apex:page controller="sample">

<script type="text/javascript">

</script>
    
    <apex:form >
    
    <apex:pageMessages />
    
    <apex:pageBlock >
        <apex:pageBlockSection columns="2">
            <apex:pageblockSectionItem >
                <apex:outputLabel value="Metro"/>
            </apex:pageblockSectionItem>        
            <apex:pageblockSectionItem >                
                <apex:inputCheckbox value="{!metro}">             
                    <apex:actionSupport event="onchange" reRender="a" action="{!demo}"/>
                </apex:inputCheckbox>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel value="City"/>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:inputCheckbox value="{!city}" id="a" disabled="{!bool}"/>
            </apex:pageblockSectionItem>            
        </apex:pageBlockSection>        
    </apex:pageBlock>

    </apex:form>

</apex:page>

 

 

 

 

public class sample
{    
    public Boolean metro {get;set;}
    public Boolean city {get;set;}
    public Boolean bool {get;set;}
    
    public sample()
    {
        
    }
    
    public void demo()
    {
        if(metro)
        {
            bool = true;
        }
        else
        {
            bool = false;
        }         
    }
      
}

 

Regards,

Magulan D

Salesforce.com certified Force.com Developer.

 

SFDC Blog

 

If this post is your solution, kindly mark this as the solution.