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 BayyaSFDC Bayya 

compare radio button with one field?

how can compare selecetde radio button value wiyh one field ..

AshlekhAshlekh
Hi,

Please elaborate more your problem.
Shyam BhundiaShyam Bhundia
This should help you:

Visualforce page snippet - this displays the radio button list and a button
<apex:selectRadio value="{!selectedValue}">
 	<apex:selectOptions value="{!options}"/>
 </apex:selectRadio>
 <apex:commandButton value="Compare" action="{!doCompare}"/>

Controller snippet - this populated the select option for the radio button.  The doComare method is called when the compare button is clicked.  The doCompare compares the current selected value to a variable called fieldToMatch
public List<SelectOption> getOptions() {
    List<SelectOption> options = new List<SelectOption>(); 
    options.add(new SelectOption('One','1')); 
    options.add(new SelectOption('Two','2')); 
    options.add(new SelectOption('Three','3')); 

    return options; 
}

public void doCompare(){
     String fieldToMatch = 'One'
     if(selectedValue == fieldToMatch){
	//they match
      }
      else{
	//they do not match
      }
}

Hope this helps :)
Ankit AroraAnkit Arora
I hope you've created a wrapper and by that you are displayed a radio and a value against it? If this is not a case then would recommend you to write a wrapper class in which you can keep two attributes one for radio selection and other is for the value. Once radio is selected you can get the value in apex and you can compare it with any other value in same class. I hope that makes sense.
SFDC BayyaSFDC Bayya
i created 6 fields :
1)question
2)answer
3)option A
option B
option C
option D

these values i displayed in vf page by using pagenation.
option A
option B
option C
option D
these fields shown as radio buttons
if choos one option that shoul comapre with answer field


Shyam BhundiaShyam Bhundia
seems like you can use the above sample code i posted.  just change the fieldToMatch attribute on doCompare method with answer.
SFDC BayyaSFDC Bayya
options.add(new SelectOption('One','1'));
    options.add(new SelectOption('Two','2'));
    options.add(new SelectOption('Three','3'));

can  i add my field values in place of one,two? 
Shyam BhundiaShyam Bhundia
So the '1' is the label which is shown on your visualforce page, and if '1' is selected, selectedValue attribute will have the value "One".  Check out this link for more details: https://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_selectoption.htm