×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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? by simmerdown
Posted: 11 Oct 01

one)
Query the database to get the list of items for display in the <select> dropdown. If you'll be using the <select> to pass values (which is usually the case) make sure you're also getting the appropriate values.

<cfquery datasource="#datasource# name="list">
    SELECT Item, Value
    FROM ItemTable
    ORDER BY Item
  </cfquery>


two)
Code the <select> box to fill with your query data. The usual parts of

<form name="item_search">

and

<select name="ItemMenu">

come first, as well as the optional static first item:

  <option value="0">items:</option>

Then use <cfoutput> to loop through the results of the query, adding another <option> for each record returned.

  <cfoutput query="list">
    <option value="#Value#">#Item#</option>
  </cfoutput>


Close off the <select> box (and immediately or eventually) the form,

  </select>
</form>


and you're done.

"Run that past me again, all at once?"

<cfquery datasource="#datasource# name="list">
    SELECT Item, Value
    FROM ItemTable
    ORDER BY Item
  </cfquery>

<form name="item_search">
  <select name="ItemMenu">
    <option value="0">items:</option>
    <cfoutput query="list">
      <option value="#Value#">#Item#</option>
    </cfoutput>

  </select>
</form>


This technique can easily be applied to generating ordered and unordered html lists, populating table rows, etc.

Happy generating.

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