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

Choosing the selected item for updating <select>

LEGEND ,
Nov 01, 2006 Nov 01, 2006

Copy link to clipboard

Copied

I have a form that has multiple <select> form items. I have an update page
that allows the user to edit information. I would like the <select> to
preselect the item that matched the db entry so the user doesn't have to
reselect it each time.

The <select> is populated from a database. How can I do this?

I've done it before using a static <select> options using a <cfif>
statement.

<cfif #GetMyCase.country# EQ #id#>selected="selected"

<select name="country">
<cfoutput query="ListCountry">
<option value="#id#">#country#</option>
</cfoutput>

Thanks.


TOPICS
Advanced techniques

Views

214

Translate

Translate

Report

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 ,
Nov 01, 2006 Nov 01, 2006

Copy link to clipboard

Copied

The easy way is to use <cfselect selected="#what_you_want#">

Slightly harder, but not much is to put your cfif tag inside your option tag. You have all the code, you just have to re-arrange it slightly.

Votes

Translate

Translate

Report

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 ,
Nov 01, 2006 Nov 01, 2006

Copy link to clipboard

Copied

LATEST
The first did not work. I changed the variables in the cfif and it worked.
thanks


Votes

Translate

Translate

Report

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
Documentation