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
Abiud Amaro DiazAbiud Amaro Diaz 

How to create a picklist for a survey using visualforce

Hi all,

I'm using VisualForce for an intake survey. The first part of it is relatively easy. This is the code for First Name.

<apex:inputfield value="{!Contact.FirstName}" />

However, I can't find any guidance on how to ask a yes or no question in the intake. I would want to limit it to yes or no. Not allow anything else like "working on it" or "almost."

Anyone know of a possible answer?
Best Answer chosen by Abiud Amaro Diaz
mukesh guptamukesh gupta
Hi Abiud,

I have tested this code , it working 100% correct Please use:-

 
Visualforce page:

<apex:selectRadio value="{!searchCategory}" >
    <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
    <apex:selectOption itemValue="No" itemlabel="No"/>
   
</apex:selectRadio>


Apex:

  public String searchCategory;

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

Please MARK AS BEST ANSWER!!!!!!!

Regards
Mukesh

All Answers

Prakash NawalePrakash Nawale
Hi Abuid,

You have to use apex:selectRadio visualforce compoent to capture yes or no radio option.

Please go through https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectRadio.htm.
You can perform action based on selection with change event of component.


Please mark this as best answer if this helps to you.
GauravGargGauravGarg

Hi Abiud,

Please creeate Select Option in vf page, and create a getter setter method in controller to populate option value. Here is the sample link (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectOption.htm)

Hope this helps !!!

Thanks,

Gaurav
Skype: gaurav62990

mukesh guptamukesh gupta
Hi Abiud,

I have tested this code , it working 100% correct Please use:-

 
Visualforce page:

<apex:selectRadio value="{!searchCategory}" >
    <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
    <apex:selectOption itemValue="No" itemlabel="No"/>
   
</apex:selectRadio>


Apex:

  public String searchCategory;

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

Please MARK AS BEST ANSWER!!!!!!!

Regards
Mukesh
This was selected as the best answer