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
Oldwen AdrianoOldwen Adriano 

Pass drop down list value to Apex code

I am trying to get the selected value from my drop down list on my Visual Force page. 

Here is my page code:
User-added image

Here is my Apex code:

User-added image

What I would like to do is something simple like this:

public myFunction()
{
     string myDDLvalue = get the DDL value

     use my DDLvalue
}
----------------------------------------------
Any help is deeply appreciated!!
bob_buzzardbob_buzzard
When you click the command button, the form will be posted back and the selected element will be present in the countries property via standard Visualforce binding - although I think this should be a single string rather than an array as you can't select more than one value.

 
Oldwen AdrianoOldwen Adriano
Hi Bob,

Can you please elaborate a little more on your response?  Can you give me an example of what you are instructing me to change?  I am not completely clear on what you're saying.

Thank you very much,
OA
bob_buzzardbob_buzzard
The short answer is you don't need to do anything special to get the selected value back - just bind to a controller property and the property will be updated when the user clicks the button and will be available to your action method. The platform handles all of this for you.

However, your Countries property should be a string, not a list of strings, as the user can only select a single value from the list.  Once you have changed this, your action method can access the countries property and the user's selection will be present.