views:

71

answers:

3

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.

+7  A: 
<cfif FORM.month eq "#qGetDates.year#,#qGetDates.month#">

or

<cfif compare(FORM.month, "#qGetDates.year#,#qGetDates.month#") EQ 0>
Henry
Is there a big performance difference using compare?
cfEngineers
compare() should be the most efficient. The simple "IS" or "EQ" comparison is case-insensitive, but it has the best readability. Big performance difference? don't think so.
Henry
A: 

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

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

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

Jason Tabler