I am having a Radio button having values Yes, No. On selecting Yes I need to disable another radio button present on the same page. How this can be done. Please help ???

  • Rajat, could you include your visualforce in your question (edit) ? That will give us some more insight into what you've already wrote and tried. May 7, 2014 at 15:22

4 Answers 4


You can use apex:actionsupport to do this the SF Way:

A simple VF Page:

<apex:page controller="TestController">
                <apex:selectRadio label="Should the next question be disabled?" value="{!disabled}">
                    <apex:selectOptions value="{!yesNo}"/>
                    <apex:actionSupport event="onclick" status="stat" action="{!test}" reRender="test"/>
                <apex:outputPanel id="test">
                    <apex:selectRadio value="{!country}" disabled="{!isDisabled}">
                        <apex:selectOptions value="{!items}"/>

And the controller:

public with sharing class TestController {
    public String country{get; set;}
    public String city{get; set;}
    public String disabled{get; set;}

    public Boolean getIsDisabled() {
        return 'Y'.equals(disabled);
    public PageReference test() {
        return null;

    public List<SelectOption> getYesNo() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('Y','Yes')); 
        options.add(new SelectOption('N','No')); 
        return options; 

    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('US','US')); 
        options.add(new SelectOption('CANADA','Canada')); 
        options.add(new SelectOption('MEXICO','Mexico')); return options; 

I would suggest using jQuery or javascript to control if the fields are disabled. Salesforce lets you get the id for using javascript if you use {!$Component.idYouGaveYourElement} and that opens up a wide world of things you can do using javascript.

  • 1
    Some sample code would make the answer more useful.
    – Keith C
    May 7, 2014 at 15:23

I recommend writing your own JavaScript (using jQuery) over apex:actionSupport too.


<apex:page >
    <apex:form >
        <apex:selectRadio id="radio-1" 
                          styleClass="radio radio-1" 
                          onclick="console.log('radio-1 pressed'); shouldDisableRadio(this,'2');" >
            <apex:selectOption id="radio-1-yes" itemLabel="Yes" itemValue="Yes" />
            <apex:selectOption id="radio-1-no"  itemLabel="No"  itemValue="No" />
        <apex:selectRadio id="radio-2" 
                          styleClass="radio radio-2" 
                          onclick="console.log('radio-2 pressed');" >
            <apex:selectOption id="radio-2-yes" itemLabel="Yes" itemValue="Yes" />
            <apex:selectOption id="radio-2-no"  itemLabel="No"  itemValue="No" />
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"/>
        var j$=jQuery.noConflict();

            console.log('jQuery is working.');

        function shouldDisableRadio(thar,radioNum){
            } else{

        function toggleRadio(radioNum,disabledValue){
            var radioString='radio-'+radioNum+'-';

your below mentioned code to disable the radio buttons is not working for me. Please find my sample radio button code below.


Javascript code:-

function testmethod(rtQOptOut){
    if(rtQOptOut.value == 'Yes'){ 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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