+ Start a Discussion
Arjun y 7Arjun y 7 

How to add radio button to each page block section?

Hi All,

My requirement is to add radio button to each row to select input values in vf page. User should enter only one input field at a time.

For the below image, i need to add radio button for each page block section. In that, i will allow users to select the input value based on the radio button. User should select only one input field at one time.Can any one help me how to solve this?





User-added image
GauravGargGauravGarg
Hi Arjun

Please find below documentation on Apex Radio button, along with example:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectRadio.htm

Thanks,
Gaurav
VineetKumarVineetKumar
This cannot be solved using the <apex:selectRadio>
The reason being, it will span accross one div or a single page block section. But your requirement is to have it accross different page sections.

You will have to use <apex:inputCheckbox> accross multiple page block sections, and use JS to select or unselect the checkboxes on more than one selection. Something like below :
<apex:inputCheckbox label="C1" id="c1" value="{!c1}" onchange="checkOne(this)"/>
<apex:inputCheckbox label="C2" id="c2" value="{!c2}" onchange="checkOne(this)"/>
<apex:inputCheckbox label="C3" id="c3" value="{!c3}" onchange="checkOne(this)"/>

function checkOne(comId){
var elements = document.getElementsByTagName("input");
    for(var i=1; i<elements.length; i++){
        if(elements[i].id != comId){
			elements[i].checked=false;
        }