• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Problem showing selected item with cfselect binding

Explorer ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

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

TOPICS
Getting started

Views

164

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Nov 08, 2022 Nov 08, 2022

Hi Charlie, thank you so much for the answer to cfselect. I got it working nicely. As for the cfdump I remember on the older version of CF when I used binding like what iuse here with cfselect case here (<cfselect name="StateCode" bind="cfc:cfcomponents.DependentSelect.GetStates()" selected="#GetUser.State#" bindonload="true" required="yes value="#Trim(GetUser.State)#"/>)  I kind of remember I have to put something in the url to get a small window pop up with some debug codes on it. But I can't

...

Votes

Translate

Translate
Community Expert ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

Selected would be set to a string (or a variable), such that would match one of  your getuser.state values being put in the "value" attribute.

 

As for a cfdump, you could dump the form scope, or form.statecode specifically--at lest after they hit submit (if you add one) or press enter while on a text field. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

Hi Charlie, thank you so much for the answer to cfselect. I got it working nicely. As for the cfdump I remember on the older version of CF when I used binding like what iuse here with cfselect case here (<cfselect name="StateCode" bind="cfc:cfcomponents.DependentSelect.GetStates()" selected="#GetUser.State#" bindonload="true" required="yes value="#Trim(GetUser.State)#"/>)  I kind of remember I have to put something in the url to get a small window pop up with some debug codes on it. But I can't exactly remember how to do it now since I have not worked with CF for awhile. What I did in the past when I used binding and wanted to know why I got the error I think I did something to get that window opo up to see the debug codes while I was still in the form and hit submit(?)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

LATEST

Sorry I missed your follow-up question. I think what you're thinking of (the ?cfdebug feature) is discussed in the docs here.

 

BTW, if that helps you, then if this answered the second part and my first one answered the first part, I hope you will mark both of them as answers. It's ok to have more than one reply marked as an answer. (And we "Adobe community professionals" do get assessed based on both how many replies we offer and how many are marked as answers.)


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation