Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Salesforce by (11.9k points)

I have a requirement in which a Text field has to be made editable or rendered when a check box is checked, how can I achieve this?

1 Answer

0 votes
by (32.1k points)
edited by

Here is a code in Visualforce which will work:

<apex:pageBlock id="theBlock">

   <apex:inputCheckbox value="{!theSObject.CheckBox__c}">

      <apex:actionSupport event="onchange" rerender="theBlock"/>


   <apex:inputText value="{!theSObject.TextField__c}" disabled="false" rendered="{!(theSObject.CheckBox__c == true)}"/>

   <apex:inputText value="{!theSObject.TextField__c}" disabled="true" rendered="{!(theSObject.CheckBox__c != true)}"/>

   <!-- Or to simply have a field that appears only when the box is checked -->

   <apex:inputText value="{!theSObject.TextField__c}" rendered="{!(theSObject.CheckBox__c == true)}"/>


Are you interested in learning Salesforce from the basics! Refer to this video on salesforce provided by Intellipaat:

In addition to this, you can add an action in the action support if you wish to do further processing in Apex, like this:

<apex:actionSupport event="onchange" action="{!myMethod}" rerender="theBlock"/>

Note: The actionSupport event for a checkbox should be on click, on change is not reliable across all browsers.

Browse Categories