Radio Button in Salesforce


To create Radio button using apex, use <apex:selectRadio>

Example:

Visualforce page:

<apex:selectRadio value="{!searchCategory}" >
    <apex:selectOption itemValue="Member" itemlabel="Member"/>
    <apex:selectOption itemValue="Blog" itemlabel="Blog"/>
    <apex:selectOption itemValue="Photo" itemlabel="Photo"/>
</apex:selectRadio>


Apex:

public String searchCategory;

public String getsearchCategory()
{
return searchCategory;
}

public void setsearchCategory(String searchCategory)
{
this.searchCategory = searchCategory;
}

2 comments:

  1. I have a group of 3 radio buttons. I want to dynamically check one of the radio button based on some condition. How do I make this work.
    <input type="radio" name="optionsRadios" id="" value="option2" checked="if((account.Phone_Type_1__c==account.Preferred_Contact_Type__c),true,false)"
    <input type="radio" name="optionsRadios" id="" value="option2" checked="if((account.Phone_Type_2__c==account.Preferred_Contact_Type__c),true,false)"
    <input type="radio" name="optionsRadios" id="" value="option2" checked="if((account.Phone_Type_3__c==account.Preferred_Contact_Type__c),true,false)"


    Preferred_Contact_Type__c is a text field
    Phone_Type_1__c
    Phone_Type_2__c
    Phone_Type_3__c

    these all r pick list fields with value work , home ,fax
    and user enters value in Preferred_Contact_Type__c
    which if matched should select desired radio button

    In this by default the last radio button is selected i want that if the pick list value and preferred text field matches then only it shud be pre selected....how can i do this??

    ReplyDelete
  2. good post but how can i create radio option dynamically with the data of Sobject,

    ReplyDelete