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

Setting selected in cfselect via a database

Explorer ,
Dec 14, 2007 Dec 14, 2007

Copy link to clipboard

Copied

Can anyone help me with this? I am returning a record form a database into a flash form. I can return the details to the form no problem but I am having a problem with the cfselect items which I have in my form. I want them to display the correct item rather than just the default but I don’t know the syntax to make them selected using the value I return from the database.

So far I have

<cfselect id="hear_about_us" name="hear_about_us" label="How did you hear about Chilli?" required="yes" message="How did you hear about Chilli?" width="180" selected="#hear_about_us#">

If I put it as an text field it returns the correct value so I know its passing the right data its just that the select doesn’t seem to work.

Any help would be greatly appreciated.
TOPICS
Advanced techniques

Views

450

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

Participant , Dec 17, 2007 Dec 17, 2007
Ah. Then the 'selected' attribute of the cfselect tag is meaningless -- strip it out. I take it you're generating a number of <option> tags, then? If that's the case, you'd do this:

<option value="theVal" <cfif theVal eq hear_about_us>selected="selected">option text</option>

plain ol' HTML to the rescue, eh?

Votes

Translate

Translate
Mentor ,
Dec 14, 2007 Dec 14, 2007

Copy link to clipboard

Copied

Are you getting your cfselect values from a query? If so, use the query attribute of the cfselect tag.

Phil

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
Participant ,
Dec 14, 2007 Dec 14, 2007

Copy link to clipboard

Copied

You'll also want to add 'value' and 'display' attributes if the cfselect is query-driven.

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 ,
Dec 15, 2007 Dec 15, 2007

Copy link to clipboard

Copied

Hi guys thanks for your help sorry I should have said that this cfselect does not get the values from a query but I will try that with my other cfselect that does. What do I need to do different if the values are hard coded?

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
Participant ,
Dec 17, 2007 Dec 17, 2007

Copy link to clipboard

Copied

Ah. Then the 'selected' attribute of the cfselect tag is meaningless -- strip it out. I take it you're generating a number of <option> tags, then? If that's the case, you'd do this:

<option value="theVal" <cfif theVal eq hear_about_us>selected="selected">option text</option>

plain ol' HTML to the rescue, eh?

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 ,
Dec 18, 2007 Dec 18, 2007

Copy link to clipboard

Copied

LATEST
Ah yes brilliant point now I feel slightly stupid.

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