I have an update page with a cfselect populated from a query. I need the selected value to be = to a value from a different query.


I can only seem to get the first item in the cfselect to display when the page loads, making me think something is wrong w/my cfselect.

This tag, btw, is w/in a <cfoutput> tag from the other query.


ex:

<cfquery name="QUERY1">
SELECT tblMain.Name as name, tblMain.Other_Name, tblMain.TrussTypeID

FROM tblMain

</cfquery>

 

<!-- get list of all truss types -->

<cfquery2 name="QUERY2>

SELECT lkuTruss.TrussTypeID, lkuTruss.TrussType
FROM lkuTruss
ORDER BY lkuTruss.TrussType
</cfquery>

 

<cfoutput query="QUERY1">

<table>.....etc.

<td>

<!--populate select box w/all possible truss types.  Have matching truss type for selected record pre-displayed-->

<cfselect name="i_p_select" query="QUERY2" value="TrussTypeID"  display="TrussType" selected="#QUERY1.TrussTypeID#" />

etc etc...

</table>

</cfoutput>

The most common cause is the value you're trying to select does not exist in the values used to populate your list.

For one thing, QUERY1 appears to be selecting all records from tblMain. So when you use selected="#QUERY1.TrussTypeID#" CF will use the value in the first record of the query only. So perhaps that's your problem.

Also, I'd suggest you cfdump both #QUERY1.TrussTypeID# and #query2#. Does #query2# actually contain the _value_ #QUERY1.TrussTypeID# ?

My bad. Query1 is incomplete as I wrote it. I was trying to save space. There is a WHERE clause in it, it returns just one record, so that isn't the problem.


The most common cause is the value you're trying to select does not exist in the values used to populate your list.

For one thing, QUERY1 appears to be selecting all records from tblMain. So when you use selected="#QUERY1.TrussTypeID#" CF will use the value in the first record of the query only. So perhaps that's your problem.

Also, I'd suggest you cfdump both #QUERY1.TrussTypeID# and #query2#. Does #query2# actually contain the _value_ #QUERY1.TrussTypeID# ?

And what about the rest? The best way to figure out why the query isn't selecting anything is to cfdump the data it's using. It could be you're using a totally wrong value. But you won't know it unless you see the values

<cfdump var="#query1#">
<cfdump var="#query2#">

Very true... I didn't put all those details here, trying to keep it short. my bad. My queries are perfectly fine.

I ended up abandoning cfselect b/c I couldn't quite get that selected attribute to pan out.
Instead, I used a regular <select>

<CFOUTPUT QUERY="query1"><CFSET xx=#TrussTypeID#></CFOUTPUT>

<select name="i_p_select"><CFOUTPUT QUERY="query2"><option value="#TrussTypeID#"<CFIF #xx# IS #TrussTypeID#>Selected</CFIF>>#TrussType#</option></CFOUTPUT></SELECT>

And what about the rest? The best way to figure out why the query isn't selecting anything is to cfdump the data it's using. It could be you're using a totally wrong value. But you won't know it unless you see the values

<cfdump var="#query1#">
<cfdump var="#query2#">

No, I didn't mean you had to post the results. Just asking if you tried the basic troubleshooting techniques I mentioned. Since cfselect's definitely do work, it must have been something in your code. (I guess I'm just stubborn and curious. I wouldn't have been able rest until I found the problem in my code ;-) But glad you have something working now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.