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
Nidhi Sharma 13Nidhi Sharma 13 

Input Field visible only if radio button option "yes" checked


I want that output label - "How many sub-projects" and input field be visible only when radio button "yes" is checked, otherwise invisible. How can I do it in VF


Please refer to code
<apex:pageBlockSection title="Project Details">
       <apex:panelGrid columns="2">
        <apex:outputLabel value="Project Name" for="gprojectName"/>
        <apex:inputField id="gprojectName" value="{!}"/>
      <apex:pageBlockSection title="Decision">
       <apex:panelGrid columns="2">
          <apex:outputLabel value="Does it have sub-project(s)?" 
          <apex:selectRadio id="radiobtn">
          <apex:selectOption id="radiobtn1" itemLabel="No" itemValue="1"></apex:selectOption>
          <apex:selectOption id="radiobtn2" itemLabel="Yes" itemValue="2"></apex:selectOption>
              <apex:outputLabel id="labid" value="How many sub-projects" for="gsubproject"/>
              <apex:inputField id="gsubproject" value="{!gproject.sub}"/>

You can use controller class with 2 steps:

1st create variable in class to set true/false based on checkbox selection.

Then , use rendered attribute on output label to the value of the above variable. So only when checkbox is select, rendered will be true and displayed.
David OvellaDavid Ovella
Hello Nidhi

this is an example of rendered a pageblock depending of some criteria
<apex:page standardController="Account">
        <apex:pageBlock mode="edit" >
            <apex:pageBlockSection title="Decision">
                <apex:actionRegion > 
                    <apex:outputLabel value="Account Source"/> 
                    <apex:inputField value="{!Account.AccountSource}">                                                        
                        <apex:actionSupport event="onchange" reRender="xxx"/>                                                        

        <apex:pageBlock mode="edit" id="xxx">                            
            <apex:pageBlockSection title="Informacion sobre el Cobro" rendered="{!IF(Account.AccountSource=='Partner',True,False)}">                                          
                <apex:inputField value="{!Account.Phone}"/>            
                <apex:inputField value="{!Account.Description}"/>