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>
</select>

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

<script>
function sample()
{
    var temp = document.getElementById(“myId”).value;
}
</script>




(Or)


<apex:page Controller=”Delet”>

<apex:form >


  <center>

  <apex:pageBlock >
    <b>Category:&nbsp;&nbsp;</b>
    <apex:selectList value=”{!ctgry}” size=”1″>
      <apex:selectOptions value=”{!ctgrys}”/>
    </apex:selectList> 
  </apex:pageBlock>
  </center>
 
</apex:form>
</apex:page>


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;
    }   

}



Cheers!!!

Leave a Reply