Two radio buttons are present with two options to select. User can select only one .

<div class="slds-col slds-size--1-of-3">   
    <input id="Quarterlyselector" type="radio" name="myRadio" value="Q" checked="checked" > Quarterly </input>                               
<div class="slds-col slds-size--1-of-2">
    <input id="Monthlyselector" type="radio" name="myRadio" value="M" > Monthly </input>

What would be the syntax to assign the user selection to a variable , so that it can be passed on to apex as a method parameter?

  • check out this answer this will help you out.
    – Praveen
    Commented May 14, 2016 at 17:37
  • 3
    I agree that there already seems to be an answer to your question.
    – Adrian Larson
    Commented May 14, 2016 at 18:18
  • the example talks abou Param tag . I don't think I'll have option to use that in my code. Can anyone help me with JS syntax. Will it be something like Var option = myradio.value? Commented May 14, 2016 at 19:08
  • 1
    Why you couldn't use apex:param? you're not able to modify controller? Commented May 14, 2016 at 19:19

1 Answer 1


You can pass selected value to controller within apex:inputhidden.

In the following example commandbutton executes JS, which looks for radio element and assign its value to inputhidden component:


<script type="text/javascript">
function CaptureRadio() {
    var y = document.querySelectorAll('[id$="HiddenInput"]')[0];
    var radios = document.getElementsByName('myRadio');
    for (var i = 0, length = radios.length; i < length; i++) {
        if (radios[i].checked) {
            y.value = radios[i].value;


<apex:pageBlock >          
    <input type="radio" name="myRadio" value="Q" checked="checked" >  
    <input type="radio" name="myRadio" value="M" >  
    <apex:commandButton value="Proceed" onclick="CaptureRadio();" 
        action="{!proceed}" rerender="theHiddenInput"/>
    <apex:inputHidden id="theHiddenInput" value="{!selected}" />


public string selected {get;set;}
public void proceed() {
    system.debug('selected: ' + selected);
  • Considering that the radio buttons are getting displayed using JS only and not apex , How can I assign the selected value to any variable? Commented May 14, 2016 at 19:41
  • @Vanilla_Sky The posted code has no dependency on page load DOM. The elements just have to exist when you click the button.
    – Adrian Larson
    Commented May 14, 2016 at 20:04
  • @AdrianLarson - Okay . Can I pass it as a parameter in my Remote Action method? Commented May 16, 2016 at 10:21

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