I want to select only One row of table using apex:selectRadio.. please share some code or helping link if any.. Thank You.. when i click or check one radio button other should be unchecked according to my requirements ..

VF page

Apex Controller

public class table
    public list  emp;
    public table()
        emp= [select id, name from employ__c ];
    public list emp_p
            return emp;

VF Page

 <apex:page controller="table">  
 <apex:pageblockTable value="{!emp_p}" var="e">
 <apex:column headerValue="select">
 <apex:column headerValue="Name" value="{!e.name}"/>

  • Have you already tried anything ? You're far more likely to get helpful answers if you put more effort into a question. Explain what you are trying to do, what you have tried and specificly is blocking you or what you have trouble understanding. The better others understand your question, the better they'll be able to help. – Samuel De Rycke Feb 2 '15 at 8:39
  • Please can you provide your source code? - It could be as simple as appending Limit 1 to your SOQL query. – developer__c Feb 2 '15 at 9:36
  • @www__c i've edited my post .. now please have a look.. – SF Dev Feb 2 '15 at 9:57
  • @SamuelDeRycke sorry now i edited my post can u please help me now .. – SF Dev Feb 2 '15 at 9:58

You need to replace :


by :

VF page :

<apex:selectRadio value="{!e.name}" styleClass="myChk" onclick="changeValue(this)">

<script type="text/javascript">
    function changeValue(radioButton) {
        var chk = document.getElementsByClassName('myChk');

        for (var i=0; i<chk.length; i++) {
            if(radioButton.value == chk[i].value) {
                chk[i].checked = true;
            } else {
                chk[i].checked = false;

In this example, I assume the Name is unique. If it's not the case, change this to have a unique reference for each item.

  • by replacing it now i have two radio button in single row.. i need only one radio button in each row by selecting one radio button others should be unchecked.. – SF Dev Feb 2 '15 at 10:28
  • Ah, ok, i see. Check my updated answer. – SF_user Feb 2 '15 at 10:55
  • still the same issue i can select more than one rows .. :( – SF Dev Feb 2 '15 at 11:17
  • Did you put an unique value as describe in the answer ? And I replace the onchange event by onclick. Does it change something ? – SF_user Feb 2 '15 at 11:48
  • yes .. and i also try html-class instead of styleclass ... by using html-class and onchange when i click on one radio button all buttons are checked.. – SF Dev Feb 2 '15 at 11:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.