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

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


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.
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.

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

Hope this helps!