2

I want to pass parameter that selected from html select tag to my controller (assign it to string "city") what should i do to achieve this ?

--Visualforce--

<select> 
      <option value="" selected="selected" disabled="disabled">City</option> 
      <option value="City A">City A</option> 
      <option value="City B">City B</option> 
      <option value="City C">City C</option> 
</select>

--Apex Class--

public String city{get;set;}

1 Answer 1

3

Use <apex:selectlist> and <apex:selectOption>

Use selected/disabled attribute of <apex:selectOption>

<apex:selectlist value="{!city}" size="1"> 
      <apex:selectOption itemlabel="City" itemValue=""/>
      <apex:selectOption itemlabel="City A" itemValue="City A"/>
      <apex:selectOption itemlabel="City B" itemValue="City B"/>
      <apex:selectOption itemlabel="City C" itemValue="City C"/>
</apex:selectlist>

Or

Use <apex:inputHidden>

<apex:inputHidden value="{!city}" id="cityId"/> 

<select onchange="document.getElementById('{!$Component.cityId}').value = this.value;"> 
      <option value="" selected="selected" disabled="disabled">City</option> 
      <option value="City A">City A</option> 
      <option value="City B">City B</option> 
      <option value="City C">City C</option> 
</select>
7
  • Hi Ratan, thanks for your response. i already try that before and it success. but i want do it with html <select> tag not <apex:selectList>. Commented Jan 5, 2016 at 4:00
  • @FebrianTarigan so it is working or not ?
    – Ratan Paul
    Commented Jan 5, 2016 at 4:01
  • need to use html <select> not <apex:selectList> Commented Jan 5, 2016 at 4:05
  • @FebrianTarigan <apex:selectList> will generate <select> ... ohk no problem check my updated Ans use <apex:inputHidden>
    – Ratan Paul
    Commented Jan 5, 2016 at 4:06
  • can i use this for multiselect true ? did it get the values or just one value ? Commented Jan 5, 2016 at 6:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .