+ 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