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

populate cfselect with existing data

New Here ,
Oct 26, 2009 Oct 26, 2009

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.)

801
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 ,
Oct 26, 2009 Oct 26, 2009

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

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
Community Beginner ,
Oct 26, 2009 Oct 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>

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
New Here ,
Oct 27, 2009 Oct 27, 2009

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

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
Community Beginner ,
Oct 29, 2009 Oct 29, 2009
LATEST

Glad I could help.

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