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

pick list values - HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Explorer ,
Nov 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

suppose the values from test01 query are "9,2,20,21,27,97,28,29,121,93,32"
when i submit the form, the chosen values are differnt from what it was selected. what did i do wrong?

In this part, <cfoutput query="test01">
<option value="#test01.index_id#" <cfif form.colorname contains test01.index_id> selected="selected"</cfif> />#test01.colorname#
</cfoutput>

I think this is not working since form.colorname has more than one value.
I want to preserve the selected values when form is submitted. If there is one value selected which means form.colorname has one value, then there is no problem; however, if it contains more than one value, the pick list has unexpected values are selected. The selected values should be selected after sumitting the form.

Anyone can correct me? I've been working this code for many hours, but i cannot think of way to correct it. I've tried list function, but it did not work for me.
TOPICS
Advanced techniques

Views

727

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

Guide , Nov 07, 2006 Nov 07, 2006
HandersonVA,

Contains will return true if one string contains another string. The expression below will output YES because the string "21,27, 97" contains the string " 9". This is not the right type of comparison for what you're trying to achieve.
<cfif "21,27,97" CONTAINS "9">
YES
</cfif>

To determine whether the value "9" is contained within a list of values, use list functions like ListFind or ListFindNoCase:
<cfif listFind("21,27,97", "9") gt 0>
YES
</cfif>

Votes

Translate

Translate
Guest
Nov 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

Your problem may be here:
CONTAINS- "Determines whether the value on the left is contained in the value on the right. Returns true if it is."
This is a quote from the CF docs. In your case, the value on the left is the 3-element list othercolornames. Try reversing the order.

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 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

You are right, something is not right with "CONTAINS" in that code.
the order cannot be controlled and it can be various. actually, variables.othercolorname is user's selections. If i use "EQ" instead of "CONTAINS", it does not work. please help

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 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

this is crazy. if the form.colorname has values of 21,27,97, it selected
9,2,21,27,97 from values in test01 query. HELP!!!!!!

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
Guide ,
Nov 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

>this is crazy. if the variables.othercolorname has values of 21,27,97, it selected
>9,2,21,27,97 from values in test01 query. HELP!!!!!!
>....
>I've tried list function, but it did not work for me

The results are right, but I think you're misunderstanding the contains function. It sounds like you should be using a list function instead. What do you mean when you say the list functions "did not work for me"?

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 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

it should be only selected "21,27,97" and not "9 and 2" since i set the values of "21, 27, 97" for form.colorname.
Also, I tried <cfif form.colorname contains ValueList(bqry01.index_id)> instead of w/o valuelist. Then when i submit the form, none of the values was selected. I think i used wrong expression. The pick list should be the same value which was set in form.colorname.

P.S Sorry for using a different variable scoop. variables.othercolorname has been changed to form.colorname.

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
Guide ,
Nov 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

HandersonVA,

Contains will return true if one string contains another string. The expression below will output YES because the string "21,27, 97" contains the string " 9". This is not the right type of comparison for what you're trying to achieve.
<cfif "21,27,97" CONTAINS "9">
YES
</cfif>

To determine whether the value "9" is contained within a list of values, use list functions like ListFind or ListFindNoCase:
<cfif listFind("21,27,97", "9") gt 0>
YES
</cfif>

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
Guest
Nov 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

Rather than using CONTAINS, do the following:
<CFIF ListFind(form.colorname, test01.index_id)>selected</CFIF>

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 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

LATEST
thank you so much, jedline and cf_dev2. thanks agin cf_dev2 for the kind explanation of "CONTAINS".

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