Skip to main content
Participant
October 26, 2009
Question

populate cfselect with existing data

  • October 26, 2009
  • 2 replies
  • 864 views

I have an update form that I am trying to populated with existing data.  For text fields, I am using the value attribute, which works fine:

<cfinput type="text" name="gender" required="no" id="gender" value="#qData.gender#"></td>

I am struggling to accomplish the same affect with a cfselect.  This following is the code used to select "Yes" or "No" for insertion into the db.

<cfselect enabled="Yes" name="primarycontact" multiple="no" id="primarycontact"><option value="Yes">Yes</option><option value="No">No</option></cfselect>

The issue that I have is how to take an exising value from qData.primarycontact and to populate the cfselect with that value (at which time the user would have the option to update it.)

    This topic has been closed for replies.

    2 replies

    glynjackson
    Participating Frequently
    October 26, 2009

    something like this?

    <cfselect enabled="Yes" name="primarycontact" multiple="no" id="primarycontact">
      <option value="Yes" <cfif qData.primarycontact is "yes">selected="selected"</cfif>>Yes</option>
    <option value="No" <cfif qData.primarycontact is "no">selected="selected"</cfif>>No</option>
    </cfselect>

    xmrjustinAuthor
    Participant
    October 27, 2009

    Yes, exactly like that.  Thank you.  I appreciate your help.

    glynjackson
    Participating Frequently
    October 29, 2009

    Glad I could help.

    Inspiring
    October 26, 2009

    Assuming the database value is either yes or no, use the selected attribute of cfselect.