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
Shyam Sundar 84Shyam Sundar 84 

HELP ME ON THIS!!!

check box and text field must be dependent, after checking the check box only you can fill the text field. Need 3 possible approaches
Khan AnasKhan Anas (Salesforce Developers) 
Hi Shyam,

Greetings to you!

1. 
Visualforce:
<apex:page id="thepage" standardController="Account" >
    <apex:form >
        <apex:pageBlock>
            <apex:pageBlockSection>
                <apex:inputField value="{!Account.Cb__c}">
                    <apex:actionSupport event="onchange" rerender="pan"/>
                </apex:inputField>
                <apex:outputPanel id="pan">
                    <apex:outputLabel value="Text Field" /> &nbsp;&nbsp;
                    <apex:inputText id="test" disabled="{!IF(Account.Cb__c==false,true,false)}" />
                </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

2. Using HTML input checkbox and input text
<apex:page>
    
    <input type="checkbox" id="yourBox" />
    <input type="text" id="yourText" disabled="true" />
    
    <script>
    document.getElementById('yourBox').onchange = function() {
        document.getElementById('yourText').disabled = !this.checked;
    };
    </script>
</apex:page>

3. using Vf and Apex:
Visualforce:
<apex:page id="thepage" standardController="Account" extensions="testComponent">
<apex:form >
    <apex:inputField value="{!acc.Name}">
        <apex:actionSupport event="onchange" action="{!changeCheckBox}" rerender="pan" />
    </apex:inputField>
            <apex:outputPanel id="pan">
            <apex:inputField id="test" value="{!acc.Cb__c}"/>
        </apex:outputPanel>
</apex:form>
</apex:page>

Controller:
public with sharing class testComponent {

    public testComponent() {

    }

    public Account acc{get;set;}
    public testComponent(ApexPages.StandardController controller) {
        acc=[select id,Name,Cb__c from account where id='Enter_Account_Id'];
    }
    public pagereference changeCheckBox(){
        acc.Cb__c=true;
        return null;
    }

}

4. Use validation rule
AND(Cb__c = TRUE, ISBLANK(Text_Field_Name__c)

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas