I have two objects Question__c and Answer__c. For every question record there will be 4 answer records. I need to have 4 answers as radio buttons for every question. How to display the answers as radio group for every question.

 <apex:pageBlock title="Questions">
 <apex:repeat value="{!questions}" var="q">

        <apex:outputField value="{!q.Question__c}"/>
          <apex:pageBlockTable value="{!q.Answers__r}" var="a">

            <apex:column >
         <apex:selectradio layout="lineDirection"> 
              <apex:selectOption itemValue="{!a.Answer__c }" itemLabel="{!a.Answer__c }">  </apex:selectOption>



I tried like this but, radio buttons aren't grouped. How to make these buttons grouped?

1 Answer 1


I had to use some JavaScript and HTML Input tag to work around this. This is extract from my code. So what this does is have an inputHidden in your code and set the value in this field in JavaScript onclick event.

<apex:pageBlockTable value="{!someList}" var="con">
<apex:column value="{!con.name}" />

    <input type="radio" name="chosen" id="{!con.id}" VALUE="{!con.id}" onclick="changeValue(this,'{!$Component.RadioButtonValue}');"/>


<apex:inputHidden value="{!contactId}" id="RadioButtonValue" />

function changeValue(input, textid) {
    document.getElementById(textid).value = input.value;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .