Copy link to clipboard
Copied
Hi,
I have a cfselect that is defined as such:
<cfselect name="ScheduledFollowup" >
<option value=""></option>
<cfloop index="fol" from="0" to="50">
<option value="<cfoutput>#fol#</cfoutput>>
<cfoutput>#fol#</cfoutput>
</option>
</cfloop>
</cfselect>
What I need to do is insert a "selected" attribute on the option that matches a value retrieved in an earlier query. I have tried imbedding a <cfif> statement but that doesn't work.
Any ideas?
OK. This code worked.
<td valign="top">
<cfselect name="ScheduledFollowup" selected="#SelectVisit.FollowUpMonths#">
<option value=""></option>
<cfloop index="fol" from="0" to="50">
<cfif fol EQ SelectVisit.FollowupMonths>
<option value="<cfoutput>#fol#</cfoutput>" selected >
<cfelse>
<option value="<cfoutput>#fol#</cfoutput>" >
</cfif>
<cfoutput>#fol#</cfoutput>
</option>
</cfloop>
</cfselect>
</td>
Copy link to clipboard
Copied
<cfselect> has a selected attribute. It always works when I use it.
Copy link to clipboard
Copied
I tried that. The documentation states that it only works when the cfselect is populated from a query.
Copy link to clipboard
Copied
You could always fake a query for the #fol#.
<cfscript>
tmp = QueryNew("field1","{datatype}");
tmp2 = QueryAddRows(tmp,x); <!--- x being the number of rows --->
tmp3 = QuerySetCell(tmp,"field1","{value}",1);
tmp3 = QuerySetCell(tmp,"field1","{value}",2);
...
</cfscript>
<cfdump var="#tmp#">
<cfoutput query="tmp">
#field1#<br />
</cfoutput>
^_^
Copy link to clipboard
Copied
I have tried this without success:
<tr id="ScheduledFollowupRow">
<td valign="top">Scheduled Follow Up<br/>(Number of Months)</td>
<td valign="top">
<cfset Selected = "">
<cfselect name="ScheduledFollowup" >
<option value=""></option>
<cfloop index="fol" from="0" to="50">
<cfif fol EQ #SelectVisit.FollowupMonths#>
<cfset Selected = " selected">
</cfif>
<option value="<cfoutput>#fol# #Selected#</cfoutput>">
<cfoutput>#fol#</cfoutput>
</option>
</cfloop>
</cfselect>
</td>
</tr>
What am I doing wrong?
Copy link to clipboard
Copied
OK. This code worked.
<td valign="top">
<cfselect name="ScheduledFollowup" selected="#SelectVisit.FollowUpMonths#">
<option value=""></option>
<cfloop index="fol" from="0" to="50">
<cfif fol EQ SelectVisit.FollowupMonths>
<option value="<cfoutput>#fol#</cfoutput>" selected >
<cfelse>
<option value="<cfoutput>#fol#</cfoutput>" >
</cfif>
<cfoutput>#fol#</cfoutput>
</option>
</cfloop>
</cfselect>
</td>