Copy link to clipboard
Copied
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.)
Copy link to clipboard
Copied
Assuming the database value is either yes or no, use the selected attribute of cfselect.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
Yes, exactly like that. Thank you. I appreciate your help.
Copy link to clipboard
Copied
Glad I could help.