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
Neal03416264103989518Neal03416264103989518 

How to grey out (disable) an apex:inputField based on the value defined in a checkbox?

Hi,

I have a check box field and an apex: inputfield on a visualforce page. The page should initally load with apex:inputfield as readonly (greyout) and as soon as the user ticks the checkbox the field should be available for entering text. How can I achieve this using Javascript?

Thank You.
izay.ramos-irizarry1.3893936724146558E12izay.ramos-irizarry1.3893936724146558E12
Add an action support to the apex:checkbox and reRender the block where the apex textfield is located. Use the value in the checkbox on the disable attribute for the apex textField to enable disable it based on that value.

Ex.:
<apex:inputCheckbox value="{!myBoolean}">
    <apex:actionSupport event="onclick" reRender="myPanel"/>
</apex:inputCheckbox>
<apex:outputPanel id="myPanel">
    <apex:inputText value="{!myString}" disabled="{!myBoolean}"/>
</apex:outputPanel>

Hope this helps!