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

get a dynamic cfselect to remember a selected value

Community Beginner ,
Jan 31, 2010 Jan 31, 2010

Copy link to clipboard

Copied

Hello;

How do I get a cfselect to remember a value if a user has selected one of the choices, but forgets to fill out another form field?

here is my select:

<cfselect enabled="No" name="state" size="1" class="formSelect" multiple="no">
                <option value="">--Select a State--</option>
                <cfloop query= "SESSION.stat">
                  <option value="#state#">#state#</option>
                </cfloop></cfselect>

Everything works accept for remembering what a user chooses I usually use something like value="#form.state#" but it doesn't work in this insance. Can anyone help me? I can't figure this out.

thanks

TOPICS
Advanced techniques

Views

1.4K

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

LEGEND , Jan 31, 2010 Jan 31, 2010

What is the benefit of storing the query in the session scope, on top of caching the query?


Especially as the query is pulling out a list of states.  It's not like the recordset is going to be different from one person (session) to the next..?

Also: probably best to ORDER that list of states by something...

--

Adam

Votes

Translate

Translate
LEGEND ,
Jan 31, 2010 Jan 31, 2010

Copy link to clipboard

Copied

Step 1 - do a query of queries to get ---Select a State--- as the first row of that query.

Step 2  - in your cfselect, use the query and selected attributes instead of the loop.

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 Beginner ,
Jan 31, 2010 Jan 31, 2010

Copy link to clipboard

Copied

I have to use a loop, it's embeded inside a cfoutput and I don't need to use he q

uery to set up the form. it goes like this:

<cfquery name="SESSION.stat" datasource="#APPLICATION.dataSource#" cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#">
SELECT state, ID
FROM States
</cfquery>

then the form:

<cfoutput>

<cfform action="#cgi.script_name#" method="post">

<cfinput type="text" name="name" id="name" value="#form.name#">

My select:

<cfselect enabled="No" name="state" size="1" class="formSelect" multiple="no">
                <option value="">--Select a State--</option>
                <cfloop query= "SESSION.stat">
                  <option value="#state#">#state#</option>
                </cfloop></cfselect>

</cfform>

</cfoutput>


How would I make this work and remember what they selected if they forgot to type in their name? (There are a bunch of fields in this form, I just pulled the one so you see what's going on.)

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
Valorous Hero ,
Jan 31, 2010 Jan 31, 2010

Copy link to clipboard

Copied

I have to use a loop, it's embeded inside a cfoutput

No, you do not "have to" use a loop. As Dan suggested, you can use "the query and selected attributes" of cfselect. This replaces the cfloop. CF uses the query and column names you supply to populate the select list automatically. Likewise, it uses whatever "selected" attribute you supply value to pre-select the desired list option.

<cfquery name="SESSION.stat"

datasource="#APPLICATION.dataSource#"

cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#">

What is the benefit of storing the query in the session scope, on top of caching the query?

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
LEGEND ,
Jan 31, 2010 Jan 31, 2010

Copy link to clipboard

Copied

What is the benefit of storing the query in the session scope, on top of caching the query?


Especially as the query is pulling out a list of states.  It's not like the recordset is going to be different from one person (session) to the next..?

Also: probably best to ORDER that list of states by something...

--

Adam

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 Beginner ,
Jan 31, 2010 Jan 31, 2010

Copy link to clipboard

Copied

That fixed it, thank you! I was still working the old way. back in 5. Forg

ot 8 is so much easier to use in some respects. Works noce now. Thanks again

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
LEGEND ,
Jan 31, 2010 Jan 31, 2010

Copy link to clipboard

Copied

LATEST

I think Dan (rather than me, as you've marked it) probably answered your question here, but not to worry: at least you got there in the end.

If you're coming from CF5, it might be a good idea to go to the CF8 docs and read the bit on "what's changed since CF5", just as a refresher.

Best of luck.

--

Adam

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