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
Del_SantosDel_Santos 

Diabling multiple fields using the single checkbox

Hi! Hello!

 

Can you help me on how can i use a single checkbox to disable multiple fields. I have this code below which disable the field {!Lead.Billing_House__c} when the checkbox {!Lead.Cpy_from_Installation_Address__c} is seleceted, however i want to disable more field using the same checkbox, and i cant use the same id because the system tells me already duplicate id.

 

 

<apex:pageBlockSection title="Billing Address" collapsible="false" columns="1">
<apex:inputCheckbox value="{!Lead.Cpy_from_Installation_Address__c}" onchange="document.getElementById('{!$Component.disablefield}'.disabled=this.checked"/>
    <apex:inputField id="disablefield" value="{!Lead.Billing_House__c}"/>
    <apex:inputField  value="{!Lead.Billing_Apartment__c}"/>
    <apex:inputField  value="{!Lead.Billing_Street__c}"/>
    <apex:inputField  value="{!Lead.Billing_Subdivision__c}"/>
    <apex:inputField  value="{!Lead.Billing_City__c}"/>
    <apex:inputField  value="{!Lead.Billing_Zip_Code__c}"/>
</apex:pageBlockSection>

 

Thanks in AdvancE!

 

Del

yvk431yvk431

Instead of diabling only the checkbox why dont you call a javascript script function and disable all the fields ?

 

 

--yvk

Del_SantosDel_Santos

Hi,

 

Thanks for the suggestion, cann you give me a sample? :)

 

Thanks!

Del

 

 

MarrisMarris

Hi Del

 

        I hope that this script might help you to solve your problem. This will disable all fields in Lead below when you check the checkbox named 'Check Me'  and enable all the fields when you uncheck the checkbox

 

 <!-- Script that disables all the field when you check the checkbox and disable it when you do viceversa -->

<apex:page standardController="Lead">
<script>
    function disableAllFields(){
    var f = document.getElementsByTagName('input');
    if(document.getElementById('htmlChkBox').checked == true){
        for(var i=0;i<f.length;i++){
            if(f[i].getAttribute('type')=='text'){
                f[i].setAttribute('disabled',false)
            }
        }
    }else{
        for(var i=0;i<f.length;i++){
            if(f[i].getAttribute('type')=='text'){
                f[i].removeAttribute("disabled")
            }
        }
    }
 }
</script>


<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection title="Billing Address" collapsible="false" columns="1" >

            <Input Type="checkbox" Name="Check me" id="htmlChkBox"  onclick="disableAllFields();"> Check Me </Input>
            <apex:inputField id="disablefield" value="{!Lead.country__c}" />
            <apex:inputField value="{!Lead.city__c}"/>
            <apex:inputField value="{!Lead.state__c}"/>
 
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

</apex:page>
If this answer solves your Query . Please Mark it as solution else let me know where you are facing trouble.
Thanks
Marris