February 16, 2012

Listbox using visualforce

To create listbox, just use HTML coding

<select id = "myId">
  <option value = "ap">Apple</option>
  <option value = "oran">Orange</option>
  <option value = "pine">Pineapple</option>

To get the value in apex controller, use the below javascript

function sample()
    var temp = document.getElementById("myId").value;


<apex:page Controller="Delet">

<apex:form >


  <apex:pageBlock >
    <apex:selectList value="{!ctgry}" size="1">
      <apex:selectOptions value="{!ctgrys}"/>

Apex Controller:
public class Delet

    public String[] ctgry = new String[]{};

    public Delet()


    public List<SelectOption> getCtgrys()
      List<SelectOption> options = new List<SelectOption>();
      options.add(new SelectOption('US','US'));
      options.add(new SelectOption('CANADA','Canada'));
      options.add(new SelectOption('MEXICO','Mexico'));
      return options;
    public String[] getCtgry()
      return ctgry;
    public void setCtgry(String[] ctgry)
    this.ctgry = ctgry;


1 comment:

  1. why u put constructor and getter setter method for select list