Mohamad
Mohamad

Reputation: 35359

Does Len function only evaluate numerical results?

Why does the following code not output "Error" if the form is submitted with a blank field? Does Len only evaluate numerical values?

<cfif NOT Len(Trim("Form.myField"))>
 <cfoutput>Error</cfoutput>
</cfif>

The following also does not evaluate as expected:

<cfif Len(Trim("Form.myField")) IS 0>
 <cfoutput>Error</cfoutput>
</cfif>

HTML:

<input type="text" name="myField" value="">

Upvotes: 2

Views: 130

Answers (2)

ale
ale

Reputation: 6430

Because it's evaluating the literal string "Form.myField", which is not length 0.

Try: <cfif len(trim(form.myField)) EQ 0>

Upvotes: 5

Jason M
Jason M

Reputation: 512

are you sure you're supposed to pass in the parameter in quotes within the trim function? it may be literally trimming the string "Form.myField"

Upvotes: 1

Related Questions