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
randheer practiserandheer practise 

i have one Radio button.if i select that radio button(itemlabel) corrosponded itemvalue should display on page..can any one help me

vf page:
<apex:page controller="radiobox_Class">
 <apex:form>
  <apex:pageBlock>
   <apex:pageBlockSection >
    <apex:selectRadio label="Select Hobby" borderVisible="true" immediate="true" disabled="false" value="{!SelectGame}">
           <apex:selectOption itemlabel="FootBall" itemvalue="FB"/>
           <apex:selectOption  itemlabel="Tennis" itemvalue="TN"/>
           <apex:selectOption  itemlabel="Hockey" itemvalue="HOC"/>
           <apex:selectOption  itemlabel="CoCo" itemvalue="Co"/>
           <apex:selectOption  itemlabel="Cricket" itemvalue="Cric"/>
    </apex:selectRadio>   
       <apex:commandButton value="Show Selected game" action="{!Display}"/>
       <apex:outputLabel>your selected game code is....{!output }</apex:outputLabel>
   </apex:pageBlockSection>   
  </apex:pageBlock>   
 </apex:form>
</apex:page>

class:
public class radiobox_class {
    public string output{get;set;}
    public string SelectGame{get;set;}
    public void Display(){
        if(SelectGame=='FootBall'){
            output='FB';
        }else if(SelectGame=='Tennis'){
            output='TN';
        }else if(SelectGame=='Hockey'){
            output='HOC';
        }else if(SelectGame=='Cricket'){
            output='CIC';
        }else if(SelectGame=='CoCo'){
            output='Co';
        }else{
            output='sorry some thing went wrong';
        }
    }
}
i want through method only
THanks in Advance
Best Answer chosen by randheer practise
Dutta SouravDutta Sourav
Hi Randheer, 
Try this:
<apex:page controller="sport">
<apex:form >
    <apex:selectRadio label="Select Hobby" borderVisible="true" immediate="true" disabled="false" value="{!sports}"  >
           
          <apex:selectOption itemlabel="FootBall" itemvalue="FB"/>
           <apex:selectOption itemlabel="Tennis" itemvalue="TN"/>
           <apex:selectOption itemlabel="Hockey" itemvalue="HOC"/>
           <apex:selectOption itemlabel="CoCo" itemvalue="Co"/>
           <apex:selectOption itemlabel="Cricket" itemvalue="Cric"/>
          
    
    </apex:selectRadio>
    
    <apex:commandButton value="Show Selected game" action="{!selected}" reRender="sp"/>
 <apex:outputLabel id="sp">Select your selected game code is....{!sprt}</apex:outputLabel>
</apex:form>
</apex:page>
 
public with sharing class sport {

public String sports{get;set;}
public String sprt{get;set;}


    public PageReference selected() {
        sprt=sports;
    
        return null;
    }
}

Hope this helps!

Best Regards,
Sourav

All Answers

Dutta SouravDutta Sourav
Hi Randheer, 
Try this:
<apex:page controller="sport">
<apex:form >
    <apex:selectRadio label="Select Hobby" borderVisible="true" immediate="true" disabled="false" value="{!sports}"  >
           
          <apex:selectOption itemlabel="FootBall" itemvalue="FB"/>
           <apex:selectOption itemlabel="Tennis" itemvalue="TN"/>
           <apex:selectOption itemlabel="Hockey" itemvalue="HOC"/>
           <apex:selectOption itemlabel="CoCo" itemvalue="Co"/>
           <apex:selectOption itemlabel="Cricket" itemvalue="Cric"/>
          
    
    </apex:selectRadio>
    
    <apex:commandButton value="Show Selected game" action="{!selected}" reRender="sp"/>
 <apex:outputLabel id="sp">Select your selected game code is....{!sprt}</apex:outputLabel>
</apex:form>
</apex:page>
 
public with sharing class sport {

public String sports{get;set;}
public String sprt{get;set;}


    public PageReference selected() {
        sprt=sports;
    
        return null;
    }
}

Hope this helps!

Best Regards,
Sourav
This was selected as the best answer
Shin ChaneShin Chane

It seems like you're trying to implement a Visualforce page with radio buttons to display corresponding values. Your code looks correct, but you're encountering an issue. To help you out, could you please specify the exact problem you're facing or any error messages you're receiving? This will make it easier to provide you with a solution.For more visit : https://futbollibreenvivo.org/