Roscoeh
Roscoeh

Reputation: 59

coldfusion string comparison

I have a form that returns a list like this when submitted:

2009,9

I want to compare it to database pulled values but keep getting an error.

<cfif #FORM.month# eq #qGetDates.year#,#qGetDates.month#>

I know I probably have to cast it or convert it to a string for the comparison to work, how do I do this?

Thanks,

R.

Upvotes: 4

Views: 8442

Answers (3)

J.T.
J.T.

Reputation: 2616

You are overusing #. Unless variables are inside quotation marks or a cfoutput block, you don't use # as a general rule.

Another rule: You must use quotes around strings (the comma in this case). You can also include variables in your strings with the rule above (use #) as seen in Henry's example.

<cfif #FORM.month# eq #qGetDates.year#,#qGetDates.month#>

should have # removed and the comma needs the string concatenated

<cfif FORM.month eq qGetDates.year & "," & qGetDates.month>

Or as Henry said

Upvotes: 2

Vikas
Vikas

Reputation: 24332

If you want to get the second value (a value after first comma), then

<cfset x = "2009,7">
<cfoutput>
    #listGetAt(x,2)#
</cfoutput>

Upvotes: 1

Henry
Henry

Reputation: 32915

<cfif FORM.month eq "#qGetDates.year#,#qGetDates.month#">

or

<cfif compare(FORM.month, "#qGetDates.year#,#qGetDates.month#") EQ 0>

Upvotes: 13

Related Questions