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
madhan bondalapatimadhan bondalapati 

Selecting a radio button one at a time

Hi All i want to select a radio one at time ,but in my case i am selecting all radio buttons.Could you please help me in this issue.

I want to the save the selected values in the custom object .Here is my code for Visual force page and controller

Visualforce page :

<apex:page showHeader="false" sidebar="false" controller="SurveyContact">
<apex:pageMessages />
    <div align="center">
        <h1> Survey For Contact </h1>
    </div>
    <apex:form >
        <apex:pageBlock title="Survey Questions">
        <apex:outputPanel rendered="{!FirstScreen}">
            <apex:actionRegion >
                You will be answering a bunch of questions to plan your Long weekend in a Relaxing way. <br/>

                Click Start button below to get to your first question. <br/><br/>

                <apex:commandButton value="Start" action="{!StartSurvey}"/>
            </apex:actionRegion>
        </apex:outputPanel>
        <apex:outputPanel rendered="{!FirstQuestion}">
           <apex:actionRegion >     
            <table>       
                 <tr>
                    <td>
                        <apex:outputLabel value="Fun places to visit "/>
                    </td>
                    <td>
                        <apex:selectRadio value="{!PlaceToVisit}"/> 
                    </td>
                    <td>
                        Grand prismatic spring
                    </td>
                    <td>
                        <apex:selectRadio value="{!PlaceToVisit}"/> 
                    </td>
                     <td>
                        Grand Canyon of Yellowstone
                    </td>
                    <td>
                        <apex:selectRadio value="{!PlaceToVisit}"/> 
                    </td>
                    <td>
                       Hayden Valley
                    </td>
                    <td>
                        <apex:selectradio value="{!PlaceToVisit}"/>
                    </td>
                    <td>
                       Mammoth Springs
                    </td>                   
                    <td>
                        <apex:selectradio value="{!PlaceToVisit}"/> 
                    </td>
                    <td>
                    Norris Geyser Basin
                    </td>
                </tr>
            </table>
            <apex:commandButton value="Next" action="{!next}"/>
            
            </apex:actionRegion> 
        </apex:outputPanel>
        </apex:pageBlock>
            <!--<div align="center" draggable="false" >
                <apex:commandButton action="{!save}" value="Save"/>&nbsp;
                <apex:commandButton value="Next"/>
            </div>-->
    </apex:form>
</apex:page>

Controller:

public with sharing class SurveyContact {

  

    public String SurveySatisfaction {get;set;}
    public String PlaceToVisit {get;set;}
    public boolean FirstQuestion {get;set;}
    public boolean SecondQuestion {get;set;}
    public boolean FirstScreen {get;set;} {FirstScreen = true;}

    public PageReference save(){
    PageReference pr =new PageReference('a0W/e');
        return pr;
    }

    public void StartSurvey(){
        FirstQuestion = true;
        FirstScreen = false;
    }
      public void  next() {
       FirstQuestion=False;
       SecondQuestion=True;    
    }
    
}

 
Shashikant SharmaShashikant Sharma
Hi Madan,

Change your VFP Code to
 
<apex:page showHeader="false" sidebar="false" controller="SurveyContact">
<apex:pageMessages />
    <div align="center">
        <h1> Survey For Contact </h1>
    </div>
    <apex:form >
        <apex:pageBlock title="Survey Questions">
        <apex:outputPanel rendered="{!FirstScreen}">
            <apex:actionRegion >
                You will be answering a bunch of questions to plan your Long weekend in a Relaxing way. <br/>

                Click Start button below to get to your first question. <br/><br/>

                <apex:commandButton value="Start" action="{!StartSurvey}"/>
            </apex:actionRegion>
        </apex:outputPanel>
        <apex:outputPanel rendered="{!FirstQuestion}">
           <apex:actionRegion >     
            <table>       
                 <tr>
                    
                    <td>
                        <apex:selectRadio value="{!PlaceToVisit}">
                        
                             <apex:selectOption itemValue="Fun places to visit" itemLabel="Fun places to visit"/>
                             <apex:selectOption itemValue="Grand prismatic spring" itemLabel="Grand prismatic spring"/>
                             <apex:selectOption itemValue="Grand Canyon of Yellowstone" itemLabel="Grand Canyon of Yellowstone"/>
                             <apex:selectOption itemValue="Hayden Valley" itemLabel="Hayden Valley"/>
                             <apex:selectOption itemValue="Mammoth Springs" itemLabel="Mammoth Springs"/>
                             <apex:selectOption itemValue="Norris Geyser Basin" itemLabel="Norris Geyser Basin"/>
                             
                        </apex:selectRadio> 
                    </td>
                    
                </tr>
            </table>
            <apex:commandButton value="Next" action="{!next}"/>
            
            </apex:actionRegion> 
        </apex:outputPanel>
        </apex:pageBlock>
            <!--<div align="center" draggable="false" >
                <apex:commandButton action="{!save}" value="Save"/>&nbsp;
                <apex:commandButton value="Next"/>
            </div>-->
    </apex:form>
</apex:page>


It should work for you.

Thanks
Shashikant