Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Dynamic Population

How do I dynamically populate a <select> drop-down using <cfselect>? by ecobb
Posted: 23 May 03

**NOTE:  <cfselect> will only work with <cfform>

The <cfselect> tag is used to dynamically populate a <select> box without the use of any "option" tags.  It is a very simple and straightforward tag to use, and it saves a lot of time.  

Query the database to get the list of items you want to display in the <cfselect> box.

<cfquery datasource="#data# name="query_name">
    SELECT Display, Value
    FROM YourTable
    ORDER BY Whatever

Then, use your <cfselect> tag to display all items returned from the query.

<cfselect name="ItemName" query="query_name" value="Value" display="display"></cfselect>

That's it.  Pretty simple, huh?

Another cool feature of <cfselect> is that you have the "selected" attribute.  This allows you to choose what the default value is in the <cfselect> box, which can be very useful when returning numerous results from your query.  For example, if you have a list of Countries in alphabetical order and you didn't want the user to have to scroll to the bottom of the list for "United States", you could specify it as your "selected" and it would be the default country in your list.

Let's say this query pulls the records "Abb" (abbreviation) and "Country" from a database.  For the sake of this example, we will say that the abbreviation for United States is "US".

<cfquery datasource="#data# name="get_countries">
    SELECT Abb, Country
    FROM Countries
    ORDER BY Abb

Then, use your <cfselect> tag to display all items returned from the query.

<cfselect name="Abb" query="get_countries" value="Abb" display="countries" selected="US"></cfselect>

The above <cfselect> tag will return all countries listed in the database (displaying the country name but using the abbreviation as the value), and have "United States" selected as default.  

As I said before, this is a very simple and straightforward tag to use, and it saves a lot of time.  With just a few clicks you can easily dynamically populate a <select> box.

Back to Adobe FAQ Index
Back to Adobe Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close