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;}
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>
| improve this answer | |
  • 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>. – febriantarigan Jan 5 '16 at 4:00
  • @FebrianTarigan so it is working or not ? – Ratan Paul Jan 5 '16 at 4:01
  • need to use html <select> not <apex:selectList> – febriantarigan Jan 5 '16 at 4:05
  • @FebrianTarigan <apex:selectList> will generate <select> ... ohk no problem check my updated Ans use <apex:inputHidden> – Ratan Paul Jan 5 '16 at 4:06
  • can i use this for multiselect true ? did it get the values or just one value ? – febriantarigan Jan 5 '16 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.