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
Jonas JúniorJonas Júnior 

Disable Fields if a Checkbox Change to True in VisualForce

I need validate one checkbox. If your value change to true, the form fields should be disable until another condition be attended. This another condition is already done, but I cannot do with the fields stay disable. I need help please.

The JavaScript code:
<script>
	function disableFields(){
		if (document.getElementById('isLowIncomeCheck') == true) {
			$('tipoBaixaRenda').prop('disabled',true);
			$('tipoDocumento').prop('disabled',true);
	
			console.log('I am in disableFields method'));
			document.getElementById('tipoBaixaRenda').disabled = true;
			document.getElementById('tipoDocumento').disabled = true;
			document.getElementById('grauParentesco').disabled = true;
			document.getElementById('numDocumento').disabled = true;
			document.getElementById('clienteBeneficiado').disabled = true;
			document.getElementById('ufNascimento').disabled = true;
			document.getElementById('codigoUfc').disabled = true;
			document.getElementById('dataNascimento').disabled = true;
			//I need disable the button below too
		}
	}
</script>
The VF code:
<apex:pageBlock title="Cliente Baixa Renda" id="block1">
	<!-- I need validate the checkbox below. If it change to true the fields above should be disabled -->
	<apex:inputcheckbox id="isLowIncomeCheck" required="false" value="{!isLowIncome}">
		<apex:actionsupport oncomplete="disableFields()" event="onclick" rerender="lowIncomeForm" action="{!verifySaveLoad}" />
	</apex:inputcheckbox>
	<apex:outputPanel layout="block" id="lowIncomeForm" >
		<apex:pageBlockSection id="formBaixaRenda" rendered="{!isLowIncome}" columns="2" collapsible="true">
			<apex:inputField value="{!thisCase.CNT_O_cliente_beneficiado__c}" >
				<apex:actionSupport oncomplete="removeNoneValue()" event="onchange" action="{!isBenefited}" reRender="formBaixaRenda" />
			</apex:inputField>
			<apex:inputField id="tipoBaixaRenda" value="{!thisCase.CNT_Tipo_de_Baixa_Renda__c}" rendered="true" />
			<apex:inputField id="tipoDocumento" value="{!thisCase.CNT_Tipo_de_Documento__c}" /> 
			<apex:inputField id="grauParentesco" value="{!thisCase.CNT_Grau_de_parentesco__c}" /> 
			<apex:inputField id="numDocumento" value="{!thisCase.CNT_Numero_do_Documento__c}" /> 
			<apex:inputField id="clienteBeneficiado" rendered="{!IF(thisCase.CNT_O_cliente_beneficiado__c = 'Não', true, false)}" value="{!thisCase.CNT_Nome_do_Titular_do_Benef_cio__c}" />
			<apex:inputField id="ufNascimento" value="{!thisCase.CNT_UF_Nascimento__c}"  />
			<apex:inputField id="codigoUfc" value="{!thisCase.CNT_Codigo_UF__c}" />
			<apex:inputField id="dataNascimento" value="{!thisCase.CNT_Data_de_nascimento__c}" />
			<apex:pageBlockSectionItem />  
			<apex:commandButton style="align:left;"  value="Salvar" action="{!save}"/> 
		</apex:pageBlockSection>
	</apex:outputPanel>
</apex:pageBlock>
I will appreciate any help or suggestion.

Thanks,
Junior, Jonas C.
Best Answer chosen by Jonas Júnior
Maharajan CMaharajan C
Refer this Link :

http://salesforce-walker.blogspot.com/2015/05/enable-and-disable-inputfields-in.html

All Answers

Maharajan CMaharajan C
Refer this Link :

http://salesforce-walker.blogspot.com/2015/05/enable-and-disable-inputfields-in.html
This was selected as the best answer
Jonas JúniorJonas Júnior
Hi Maharajan!

Thanks for your help. Its worked!

Thanks,
Junior, Jonas C.