+ Start a Discussion
RbnRbn 

Re:Checkbox Dependency

Hi,

 

My requirement is when a checkbox is checked ,two corresponding input fields must be enabled or else disabled.

 

For this i have written the below code:

 

<apex:inputCheckbox value="{!Family__c.Insurance_taken_for_Loan__c}"/>
<apex:actionSupport event="onchange" rerender="theBlock"/>
<apex:inputText value="{!Family__c.Insurance_Premium_Paid__c}" disabled="true" rendered="{!(Family__c.Insurance_taken_for_Loan__c == false)}"/>
<apex:inputText value="{!Family__c.Insurance_Renewal_Date__c}" disabled="true" rendered="{!(Family__c.Insurance_taken_for_Loan__c == false)}"/>

<apex:inputCheckbox value="{!Family__c.Insurance_taken_for_Loan__c}"/>
<apex:actionSupport event="onchange" rerender="theBlock"/>
<apex:inputText value="{!Family__c.Insurance_Premium_Paid__c}" disabled="true" rendered="{!(Family__c.Insurance_taken_for_Loan__c == false)}"/>
<apex:inputText value="{!Family__c.Insurance_Renewal_Date__c}" disabled="true" rendered="{!(Family__c.Insurance_taken_for_Loan__c == false)}"/>

 

But each time i check the checkbox,the input field is not getting enabled.

 

Please help me in this context.

 

Thanks in advance.

 

Regards,

rabi

Best Answer chosen by Admin (Salesforce Developers) 
Santosh KumbarSantosh Kumbar

Try this below code

 

<apex:inputCheckbox value="{!Family__c.Insurance_taken_for_Loan__c}">
<apex:actionSupport event="onchange" rerender="theBlock"/>

</apex:inputCheckbox>
<apex:inputText value="{!Family__c.Insurance_Premium_Paid__c}" disabled="{!NOT(Family__c.Insurance_taken_for_Loan__c)}"/>
<apex:inputText value="{!Family__c.Insurance_Renewal_Date__c}" disabled="{!NOT(Family__c.Insurance_taken_for_Loan__c)}" />

 

 

 

Regards

San

www.santoshkumbar.com

All Answers

Santosh KumbarSantosh Kumbar

Try this below code

 

<apex:inputCheckbox value="{!Family__c.Insurance_taken_for_Loan__c}">
<apex:actionSupport event="onchange" rerender="theBlock"/>

</apex:inputCheckbox>
<apex:inputText value="{!Family__c.Insurance_Premium_Paid__c}" disabled="{!NOT(Family__c.Insurance_taken_for_Loan__c)}"/>
<apex:inputText value="{!Family__c.Insurance_Renewal_Date__c}" disabled="{!NOT(Family__c.Insurance_taken_for_Loan__c)}" />

 

 

 

Regards

San

www.santoshkumbar.com

This was selected as the best answer
RbnRbn

Hi San,

 

Thanks a lot for the snippet of Code.It worked out.

 

 

Thanks,
Rabi
RbnRbn

Hi San,

 

The below code works fine when the checkbox is checked,but it is throwing some error while we uncheck the checkbox

 

Error:<apex:inputText> element value must resolve to a String type!

 

 

 

Below is the code:

 

 

<apex:page standardController="Family__c" extensions="familyController">
<apex:sectionHeader title="Family Banking Edit" subtitle="New Family Banking" help="http://www.salesforce.com"/>
<apex:form >
<apex:pageBlock title="Family Banking Edit" id="theBlock">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<!--<apex:commandButton value="Save & New" action="{!saveandnew}"/>-->
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" columns="2" >
<apex:inputField value="{!Family__c.Name}" required="true"/>
<apex:inputField value="{!Family__c.Customer_Name__c}" required="true"/>
<apex:inputField value="{!Family__c.Relation_with_Customer__c}" />
<apex:inputField value="{!Family__c.Relation_s_DOB__c}" />
<apex:inputField value="{!Family__c.AnnualIncomeinUSD__c}" />
<apex:inputField value="{!Family__c.Marriage_Date__c}" />
<apex:inputField value="{!Family__c.PrimaryBankAccount__c}" />


<apex:inputCheckbox value="{!Family__c.Loan_Taken__c}">
<apex:actionSupport event="onchange" rerender="theBlock"/>

</apex:inputCheckbox>
<apex:inputText value="{!Family__c.TypeofLoan__c}" disabled="{!NOT(Family__c.Loan_Taken__c)}"/>
<apex:inputText value="{!Family__c.Loan_Amount__c}" disabled="{!NOT(Family__c.Loan_Taken__c)}" />
<apex:inputText value="{!Family__c.Loan_Tenure__c}" disabled="{!NOT(Family__c.Loan_Taken__c)}" />
<apex:inputText value="{!Family__c.EMI__c}" disabled="{!NOT(Family__c.Loan_Taken__c)}" />

<apex:inputField value="{!Family__c.Type_of_Account__c}" />
<apex:inputField value="{!Family__c.Secondary_Bank_Account__c}" />
<apex:inputField value="{!Family__c.SecondaryAccountType__c}"/>
<apex:inputField value="{!Family__c.Loan_Tenure__c}"/>
<apex:actionSupport event="onchange" rerender="theBlock"/>
<apex:inputText value="{!Family__c.Insurance_Premium_Paid__c}" rendered="{!(!Family__c.Insurance_taken_for_Loan__c)}"/>
<apex:inputCheckbox value="{!Family__c.Insurance_taken_for_Loan__c}">
<apex:actionSupport event="onchange" rerender="theBlock"/>
</apex:inputCheckbox>
<apex:inputText value="{!Family__c.Insurance_Premium_Paid__c}" disabled="{!NOT(Family__c.Insurance_taken_for_Loan__c)}"/>
<apex:inputText value="{!Family__c.Insurance_Renewal_Date__c}" disabled="{!NOT(Family__c.Insurance_taken_for_Loan__c)}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

here basically there are two checkboxes,and when we uncheck the 2 nd checkbox after unchecking the 1st one,then it is showing the error.

 

Please help me out.

 

Regards,

Rabi