Copy link to clipboard
Copied
This should be simple but I don't see it. I'm sure there is a work around or a better way to do it but I can't see to find it.
Problem: The check boxes will be checked if it finds the number 1, 4, 6 or 14
What should happen: The check boxes for 6 and 14 should only be checked because the list contains the number 6 and 14 and not 1, 4, 6 and 14.
<cfset AuditionCategory = ListAppend(AuditionCategory, 6, ",")>
<cfset AuditionCategory = ListAppend(AuditionCategory, 14, ",")>
<cfoutput>#AuditionCategory#</cfoutput>
6,14
<cfloop from="1" to="20" index="i">
<input type="checkbox" name="test" value="#i#
<cfif listContains(AuditionCategory, i, ",")>checked="checked"</cfif> />
</cfloop>
What is happening is #1, #4, #6 and #14 are being checked instead of just #6 and #14.
For some reason, it is finding 1, 4, 6 and 14 instead of just finding 6 and 14.
Can anyone tell me what the solution to this problem is? Why is it trying to break apart the number 14 as 1 and 4.
Copy link to clipboard
Copied
Just replace your "ListContains" function with "ListFind"
Like this,
<cfloop from="1" to="20" index="i">
<input type="checkbox" name="test" value="#i#
<cfif ListFind(AuditionCategory, i, ",")>checked="checked"</cfif> />
</cfloop>
HTH
Copy link to clipboard
Copied
Prefect.
What's the difference? ListFind can do numbers and strings versus ListContains only supports strings? Just wanting to know.
Copy link to clipboard
Copied
I believe that ListFind treats each list element of the substring as comparative, whereas ListContains treats each character of the list element as a comparative.
ICBW..
^_^
Copy link to clipboard
Copied
ListContains() determines whether any element in the list Contains the
value you're searching. ListFind() determines whether any element in the
list IS the value you're searching.
list1 = "Apple,Brown,Cow";
list2 = "A,B,C";
ListFind(list1, "A"); --> false, because there is no element "A"
ListFind(list2, "A"); --> true
ListContains(list1, "A"); --> true, because "Apple" contains "A"
ListContains(list2, "A"); --> true
ListContains(list1, "w"); --> true, because "Cow" contains "w"
ListContains(list2, "w"); --> false, because there is no element "w"
Copy link to clipboard
Copied
> For some reason, it is finding 1, 4, 6 and 14 instead of
> just finding 6 and 14.
That is what ListContains() does. It searches for the value +anywhere+ in the list element. So searching for "1" would match "1", "11", "14", "114", etcetera. If you wish to find whole values only (ie exact match) , use ListFind() or ListFindNoCase().
Copy link to clipboard
Copied
I see. I went back and looked at the documentation again and it was all there. I must have missed that while trying to find a solution.
Copy link to clipboard
Copied
You want ListFind() = match an entire element, not ListContains() which is
finding "4" in "14" and "1" in "14".
<cfloop from="1" to="20" index="i">
</cfloop
Copy link to clipboard
Copied
For some reason, it is finding 1, 4, 6 and 14 instead of
just finding 6 and 14.
That is what ListContains() does. It searches for the value anywhere in the list element. So searching for "1" would match "1", "11", "14", "114", etcetera. If you wish to match whole values only, then use ListFind() or ListFindNoCase().