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
Ali AbdullatifAli Abdullatif 

How to make an input feild appear upon selection of radio button?

Hello friends

I have 3 feilds in my form and I need to update only one of them based on a selection
the problem is I want to be able to click a bottun and have the corresponding input field appear or disappear 
is there any way to do that?
Best Answer chosen by Ali Abdullatif
Bryan JamesBryan James
By using an apex:actionFunction to rerender an apex:outputPanel everytime a user clicks a checkbox you can allow different elements on the page to be rendered based on the value of the checkbox field.

<apex:form>
        <apex:actionFunction name="rerenderBlock" action="{!debugLog}" reRender="pb"/>
        <apex:outputPanel id="pb">
            <apex:pageBlock >
                <div>
                    <label>box1</label><apex:inputCheckbox value="{!box1}" onclick="rerenderBlock()"/>
                    <label>box2</label><apex:inputCheckbox value="{!box2}" onclick="rerenderBlock()"/>
                    <label>box3</label><apex:inputCheckbox value="{!box3}" onclick="rerenderBlock()"/>
                </div>
                <div>
                    <apex:pageBlockSection rendered="{!box1}">
                        <label>Input 1</label><apex:inputText value="{!input1}"/>
                    </apex:pageBlockSection>
                    <apex:pageBlockSection rendered="{!box2}">
                        <label>Input 2</label><apex:inputText value="{!input1}"/>
                    </apex:pageBlockSection>
                    <apex:pageBlockSection rendered="{!box3}">
                        <label>Input 3</label><apex:inputText value="{!input1}"/>
                    </apex:pageBlockSection>
                </div> 
            </apex:pageBlock>
        </apex:outputPanel>   
    </apex:form>    

All Answers

Bryan JamesBryan James
By using an apex:actionFunction to rerender an apex:outputPanel everytime a user clicks a checkbox you can allow different elements on the page to be rendered based on the value of the checkbox field.

<apex:form>
        <apex:actionFunction name="rerenderBlock" action="{!debugLog}" reRender="pb"/>
        <apex:outputPanel id="pb">
            <apex:pageBlock >
                <div>
                    <label>box1</label><apex:inputCheckbox value="{!box1}" onclick="rerenderBlock()"/>
                    <label>box2</label><apex:inputCheckbox value="{!box2}" onclick="rerenderBlock()"/>
                    <label>box3</label><apex:inputCheckbox value="{!box3}" onclick="rerenderBlock()"/>
                </div>
                <div>
                    <apex:pageBlockSection rendered="{!box1}">
                        <label>Input 1</label><apex:inputText value="{!input1}"/>
                    </apex:pageBlockSection>
                    <apex:pageBlockSection rendered="{!box2}">
                        <label>Input 2</label><apex:inputText value="{!input1}"/>
                    </apex:pageBlockSection>
                    <apex:pageBlockSection rendered="{!box3}">
                        <label>Input 3</label><apex:inputText value="{!input1}"/>
                    </apex:pageBlockSection>
                </div> 
            </apex:pageBlock>
        </apex:outputPanel>   
    </apex:form>    
This was selected as the best answer
Ali AbdullatifAli Abdullatif
thank you so much but what will the debugLog method look like in this case?