Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Populating State names dynamically

Participant ,
Mar 05, 2008 Mar 05, 2008
Hi is there a way to populate a drop down form dynamically with state names instead of doing
<select>
<option value="AK">Alaska</option>
zzz
<option value="WY">Wyoming</option>
</select>
?
340
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 05, 2008 Mar 05, 2008
I have state names and abbreviations in a database table, so I usually use something like this:

<cfquery name="getStates" datasource="#DSN#">
SELECT postal_abbreviation, name
FROM states
</cfquery>

<form name="selectState" action="index.cfm" method="POST">
<select name="state">
<cfoutput query="getStates>
<option value="#postal_abbreviation#">#name#</option>
</cfoutput>
</select>
</form>

Alternately, you could use the same query with cfselect:
<cfform name="selectState" action="index.cfm" method="POST">
<cfselect name="states" query="getStates" value="postal_abbreviation" display="name">
</cfform>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 05, 2008 Mar 05, 2008
LATEST
jenn wrote:
> Hi is there a way to populate a drop down form dynamically with state names instead of doing
> <select>
> <option value="AK">Alaska</option>
> zzz
> <option value="WY">Wyoming</option>
> </select>
> ?


If you have some kind of list, array, structure or record set of state
names and abbreviations, you can easily loop over this data and
dynamically create each <option...> tag.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources