Skip to main content
Inspiring
April 12, 2007
Question

Invalid Nested CFOUTPUT

  • April 12, 2007
  • 3 replies
  • 2501 views
I am reading from a table that contains a list of country names, and I am using it as as a dropdown. Here is what I have :

<cfquery datasource="intltransquote" name="getcntry">
SELECT * FROM country
order by cntryname
</cfquery>

<tr>
<td valign=top><font color="red">*</font>Country:</td>
<td><select name="tocntry">
<option selected value="">Scroll down to select country</option>
<cfoutput query="getcntry">
<option value="#getcntry.cntryname#">#getcntry.cntryname#</option>
</cfoutput>
</select>
</td>
</tr>

After I submit the form, I redisplay all the informational. For the dropdown, I display what was originally selected, then want to have the list available again if they want to change it. So the first item in the list should be the selected value and the rest of the list should follow. This is what I have :

<tr>
<td valign=top><font color="red">*</font>Country:</td>
<td><select name="tocntry">
<option selected value="#session.tocntry#">#session.tocntry#"</option>
<cfoutput query="getcntry">
<option value="#getcntry.cntryname#">#getcntry.cntryname#</option>
</cfoutput>
</select>
</td>
</tr>

However, I get an error about invalid nested cfoutput. Here is the error message :

Error Occurred While Processing Request
Invalid tag nesting configuration.
A query driven CFOUTPUT tag is nested inside a CFOUTPUT tag that also has a QUERY= attribute. This is not allowed. Nesting these tags implies that you want to use grouped processing. However, only the top-level tag can specify the query that drives the processing.

How do I correct this ?

    This topic has been closed for replies.

    3 replies

    Participating Frequently
    April 12, 2007
    If you're looking to loop over a query inside of a cfoutput tag, use <cfloop query="queryname">. It does the exact same thing... the only limitation is you cant use the group attribute, which you're not doing in this case. No need to keep closing and opening the cfoutput tags.
    Inspiring
    April 12, 2007
    The easiest way to solve this is to use cfselect. It has a selected attibute you can use.

    The second easiest way is to use a cfif tag inside your option tag.
    Inspiring
    April 12, 2007
    Yep, you cannot nest cfoutput except for gruop processing queries.
    You can do something like
    <cfoutput>
    html.. cf vars..
    <tr>
    <td valign=top><font color="red">*</font>Country:</td>
    <td><select name="tocntry">
    <option selected value="">Scroll down to select country</option>
    </cfoutput>

    <cfoutput query="query">
    <option value="#getcntry.cntryname#">#getcntry.cntryname#</option>
    </cfoutput>

    <cfoutput>
    </select>
    </td>
    </tr>
    ...
    ...
    ..
    </cfoutput>