Problem showing selected item with cfselect binding
How can I keep the selected item with cfselect binding? When user selected a State (Delaware) from the dropdown Alabama shows up as the first State once the form refreshed instead of Delaware. CFSELECT has a selected attribute but I don't know what value should go there and not sure if this is the one I have to use to keep the selected value. I've been searching with no luck so far, Can anyone help?
another question is how to cfdump cfselect binding to see what have is return?
DependentSelect.CFC:
<CFFUNCTION name="GetStates" access="remote" returnType="array" hint="Get US 50 States">
<!--- Define variables --->
<cfset var StateResult=ArrayNew(2)>
<cfset var i=0>
<cfquery name="q_States" datasource="#Trim(application.dsn)#">
SELECT DISTINCT StateName,StateCode
FROM States
ORDER By StateName
</cfquery>
<!--- Convert results to array --->
<cfloop index="i" from="1" to="#q_States.RecordCount#">
<cfset StateResult[i][1]=q_States.StateCode[i]>
<cfset StateResult[i][2]=q_States.StateName[i]>
</cfloop>
<CFRETURN StateResult>
</CFFUNCTION>
My ProfileForm.cfm:
<cfform id="profile" action="profileaction.cfm" method="post" enctype="multipart/form-data">
.........other form fields here.....
<label class="labels">Select your State</label>
<cfselect name="StateCode" bind="cfc:cfcomponents.DependentSelect.GetStates()" selected="??" bindonload="true" required="yes" message="Please select your State" class="smallstylebox" value="#Trim(GetUser.State)#"/>
</cfform>
I am using coldfusion 2021 on my local, SQL Server Management Studio V 18.12.1
