Skip to main content
Known Participant
August 20, 2009
Question

cfif in a cfselect

  • August 20, 2009
  • 1 reply
  • 2236 views

I am new at Flash forms and I am running into a problem when a user is editing their data.  When the user goes to their form to edit their data I want the select box to select the correct year.

If I hard code it like below then it works.

<cfselect name="dob_year" width="60">

<option value = "#the_dob_year#" <cfif #dateformat(DOB, "yyyy")# eq '1992'>selected="selected"</cfif>>1992</option>

<option value = "#the_dob_year#" <cfif #dateformat(DOB, "yyyy")# eq '1991'>selected="selected"</cfif>>1991</option>

<option value = "#the_dob_year#" <cfif #dateformat(DOB, "yyyy")# eq '1990'>selected="selected"</cfif>>1990</option>
</cfloop>
</cfselect>

But I don't want to hard code it, I want to query this data. When I use the below select box, it makes my from disappear.

<cfselect name="dob_year" width="60">
<cfloop from = "1" to = "100" index = "i">
<option value = "#the_dob_year#" <cfif #dateformat(DOB, "yyyy")# eq '#the_dob_year#'>selected="selected"</cfif>>#the_dob_year#
<cfset the_dob_year = '#the_dob_year - 1#'>
</option>
</cfloop>
</cfselect>

Any suggestions?

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    August 28, 2009

    <cfform>
    <cfselect name="dob_year" width="60">
    <cfloop from = "1" to = "100" index = "i">
    <cfoutput><option value = "#the_dob_year#" <cfif dateformat(DOB, "yyyy") eq the_dob_year>selected="selected"</cfif>>#the_dob_year#</option></cfoutput>
    <cfset the_dob_year = the_dob_year - 1>
    </cfloop>
    </cfselect>
    </cfform>