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
RbnRbn 

Disable or Enable fields depending on Checkbox Selection

Hi,

 

My req is that ,when a checkbox is checked then 4 fields(3 text fields and 1 picklist field) needs to be enabled or else it should be disabled.

 

I have achieved this functionality with 3 text fields,but i am facing problem in Picklist field since i am unable to do enable/disable.

 

 

Below is the Code:

 

<apex:inputField value="{!Liabilities__c.Type_of_Loan__c}" id="loanType"/>  // PICKLIST FIELD//
<apex:inputText value="{!Liabilities__c.Loan_Amount__c}" disabled="{!NOT(Liabilities__c.Loan_Taken__c)}" />
<apex:inputText value="{!Liabilities__c.Loan_Tenure_Years__c}" disabled="{!NOT(Liabilities__c.Loan_Taken__c)}" />
<apex:inputText value="{!Liabilities__c.EMI__c}" disabled="{!NOT(Liabilities__c.Loan_Taken__c)}" id="EMI"/>

 

Please help me in this context.

 

Thanks in Advance.

 

Regards,

Rabi

kiranmutturukiranmutturu

you can try this

 

<apex:page standardController="account">
<apex:form>
<apex:inputField value="{!account.name}"/>
<input type="checkbox" name="Test"  onchange="check(this)" value="Test"/>

<apex:inputField id="pick" value="{!account.active__c}"/>
<script>document.getElementById("{!$component.pick}").disabled=true;</script>
<script>

function check(obj)
  {
      alert(obj.checked);
      if(obj.checked == true)
         document.getElementById("{!$component.pick}").disabled=false;
      else
         document.getElementById("{!$component.pick}").disabled=true;
  }
</script>
</apex:form>
 
</apex:page>

 




this will open the picklist once you select the checkbox and by default this is disabled

RbnRbn

Hi Kiran,

Below is my Code: But i am not achieving the Enable/Disable Functionality.

<apex:inputcheckbox value="{!account.Eat_Fruits__c}" id="test" onclick="check(this)" />
<apex:inputField value="{!account.Class__c}" id="testing" />
<script> document.getElementById('j_id0:j_id1:j_id2:j_id3:testing').disabled=true;</script>
<script>
var v=document.getElementById("j_id0:j_id1:j_id2:j_id3:test").checked;
function check(obj)
{
if((v==true)){
document.getElementById("j_id0:j_id1:j_id2:j_id3:testing").disabled=false;
}
else{
document.getElementById("j_id0:j_id1:j_id2:j_id3:testing").disabled=true;
}
}

 

 

Can you please rectify me,where am i going Wrong.

Regards,
Rabi

kiranmutturukiranmutturu
try this now

<apex:inputcheckbox value="{!account.Eat_Fruits__c}" id="test" onchange="check(this)" />
<apex:inputField value="{!account.Class__c}" id="testing" />

&lt;script&gt; document.getElementById('{!$component.testing}').disabled=true;&lt;/script&gt;
&lt;script&gt;

function check(obj)
{
if((obj.checked == true)){
document.getElementById("{!$component.testing}").disabled=false;
}
else{
document.getElementById("{!$component.testing}").disabled=true;
}
}
RbnRbn

Sorry Kiran...still its not working.

 

Regards,

Rabi

kiranmutturukiranmutturu
post the complete code now what u have
RbnRbn

<apex:page standardController="account">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputcheckbox value="{!account.Eat_Fruits__c}" id="test" onclick="check(this)" />
<apex:inputField value="{!account.Class__c}" id="testing" />

&lt;script&gt; document.getElementById('j_id0:j_id1:j_id2:j_id3:testing').disabled=true;&lt;/script&gt;
&lt;script&gt;

<script>


function check(obj)
{

if((account.Eat_Fruits__c.checked == true)){

document.getElementById('j_id0:j_id1:j_id2:j_id3:testing').disabled=false;
}
else{
document.getElementById('j_id0:j_id1:j_id2:j_id3:testing').disabled=false;
}
}
else{

document.getElementById('j_id0:j_id1:j_id2:j_id3:testing').disabled=true;
}
</script>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Regards,

Rabi

kiranmutturukiranmutturu

just use the below code as it is

<apex:page standardController="account">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >


<apex:inputcheckbox value="{!account.Eat_Fruits__c}" id="test" onclick="check(this)" />
<apex:inputField value="{!account.Class__c}" id="testing" />
<script>document.getElementById('{!$component.testing}').disabled=true;</script>


<script>


function check(obj)
{

if((obj.checked == true)){

document.getElementById('{!$component.testing}').disabled=false;
}
else{
document.getElementById('{!$component.testing}').disabled=true;

}
}

</script>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

RbnRbn

Still Not Working ...  :-(

Naidu PothiniNaidu Pothini
<apex:page standardController="account">
   <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection id="pbsecId1">
               
                <apex:inputcheckbox value="{!account.Eat_Fruits__c}" id="test">
                    <apex:actionSupport event="onchange" reRender="pbsecId1"/>
                </apex:inputcheckbox>
               
                <apex:inputField value="{!account.Class__c}" id="testing" />
                <script>
                    document.getElementById('{!$Component.testing}').disabled = {!IF(account.Eat_Fruits__c, false,true)};
                </script>
            
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 will this work for you...