function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC Forum 007SFDC Forum 007 

Radio Button VF Page issue

Hi,

 

 Please help me out with my issue

 

1)I have 3 radio buttons in my vf page that i have created eg :1,2,3

2) On loading the vf page only one radio button only one radio button should be selected by default eg:3

 

Please do guide me to solve my issue

 

 

Thanks in Advance...

Best Answer chosen by Admin (Salesforce Developers) 
kamlesh_chauhankamlesh_chauhan

Here is the sample code which might helpful to you.

 

 

public class MyController{
    String SelectedRadio {get;set;}
         
    public List<SelectOption> getRadioOptions() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('1','1')); 
        options.add(new SelectOption('2','2')); 
        options.add(new SelectOption('3','3')); return options; 
    }
                   
    public MyController() {
        SelectedRadio = 3; //set default value here...
    }

}

 

Regards,

Kamlesh Chauhan, (Founder & CTO, LogicRain Technologies)

kamlesh@logicrain.com || http://www.logicrain.com || LinkedIn

 

Answers/Suggestions are my own.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

All Answers

kamlesh_chauhankamlesh_chauhan

Let us assume your code is something like below.

 

<apex:selectRadio value="{!SelectedRadio}">
    <apex:selectOptions value="{!RadioOptions}"/>
</apex:selectRadio>

 

Set the "SelectedRadio" variable to "3" (Or any default value) in the consturctor of your VF Page's controller.

 

Regards,

Kamlesh Chauhan, (Founder & CTO, LogicRain Technologies)

kamlesh@logicrain.com || http://www.logicrain.com || LinkedIn

 

Answers/Suggestions are my own.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

SFDC Forum 007SFDC Forum 007

can u guide me hw to use the default radio button value in the constructor in controller, becz i tried it disbales all the three radio buttons in it.

 

 

Thanks in advance

kamlesh_chauhankamlesh_chauhan

Do you want to disable your radio button or do you want to display any one radio button as selected?

 

Regards,

Kamlesh

SFDC Forum 007SFDC Forum 007

nopes not to disable it, want to make one radio button checked by default out of 3 radio buttons

SFDC Forum 007SFDC Forum 007

do i need to write a java script toachieve this or can i achieve this via html radio buttons

kamlesh_chauhankamlesh_chauhan

Here is the sample code which might helpful to you.

 

 

public class MyController{
    String SelectedRadio {get;set;}
         
    public List<SelectOption> getRadioOptions() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('1','1')); 
        options.add(new SelectOption('2','2')); 
        options.add(new SelectOption('3','3')); return options; 
    }
                   
    public MyController() {
        SelectedRadio = 3; //set default value here...
    }

}

 

Regards,

Kamlesh Chauhan, (Founder & CTO, LogicRain Technologies)

kamlesh@logicrain.com || http://www.logicrain.com || LinkedIn

 

Answers/Suggestions are my own.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

This was selected as the best answer
SFDC Forum 007SFDC Forum 007

Thanks a lot, It worked for me :)

 

kamlesh_chauhankamlesh_chauhan

Great. Thanks

Andrew Hoban 6Andrew Hoban 6
Can this be achieved by using a picklist value as well?