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
Pradeep PssPradeep Pss 

Get values of selectRadio in repeat

In my scenario i have a list of questions i need to capture the selected options to an object on submiting the questionaire. SelectRadio is placed inside a repeat to load questions from a master object. 

I need to get the question id and selected value of the questions and save it to an object.

VF Page
 <apex:repeat value="{!QuesList}" var="a">
     
      <apex:pageBlockSection columns="1" >
                 <apex:pageBlockSectionItem ><B>{!a.MSWq1__c}</B>
                      </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                 <apex:selectRadio layout="pageDirection" styleClass="test">
                    <apex:selectOption itemLabel="{!a.Option1__c}" itemValue="A"></apex:selectOption>
                    <apex:selectOption itemLabel="{!a.option2__c}" itemvalue="B"></apex:selectOption>
                    <apex:selectOption itemlabel="{!a.option3__c}" itemvalue="C"></apex:selectOption>
                     <apex:selectOption itemlabel="{!a.option4__c}" itemvalue="D"></apex:selectOption>
                    </apex:selectRadio> 
                 </apex:pageBlockSectionItem>
                  </apex:pageBlockSection> 
     </apex:repeat>
    </apex:pageBlock>
Controller 
 
public class ctrlQuestions {

public Assessment__c main{get; set;}
public List<master__c> QuesList {get; set;}

public ctrlQuestions(){
main=newAssessment__c();
QuesList = new List<master__c>();
QuesList = [select Name,MSWq1__c,Option1__c,Option2__c,Option3__c,Option4__c,Correct_Option_Choice__c from MSW_master__c where Isactive__c= true];
}
public PageReference saveandred() {
   insert main; 
        
        return new PageReference('/Test/'+main.Id);
    }
}

 
mritzimritzi
Add value attribute in apex:selectRadio
<apex:selectRadio layout="pageDirection" styleClass="test" value="{!radioValue}">
Add same variable in apex
 
public Assessment__c main{get; set;}
public List<master__c> QuesList {get; set;}
public String radioValue {get;set;}
If you want to store value in custom field, replace radioValue in VF with field api name (eg: main.Select_Radio_Value__c)


If this helps solve your problem, please mark this as BEST ANSWER so that others facing same situation can also benefit in future.
mritzimritzi
If the answer posted above has solved your issue, please mark it as best answer, or add details any problems you faced after implementing suggestions