Worked perfect!  I was misunderstanding the IsDefined function.  Thanks

-----Original Message-----
From: Dave Watts [mailto:[EMAIL PROTECTED]]
Sent: Saturday, July 15, 2000 12:30 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: IsDefined and CFSET problem


> The following still allows the CFSET tag to run even though
> the IsDefined variables are empty and hence an error. This is
> from a simple mail form asking for Quantity (qty1) and price
> (uc1) and then calculating a total price (tc1). If Quantity
> and Price are not filled in I want it to go to next field.
> Please make suggestions on getting this to work. I have got
> to get it working by Monday morning.
>
> <CFIF IsDefined("form.qty1") AND IsDefined("form.uc1")><cfset
> tc1 = #form.qty1# * #form.uc1#></CFIF>
>
> <CFOUTPUT>
> #form.tc1#
> </CFOUTPUT>

IsDefined tells you whether a variable exists at all, not whether it has an
empty string as a value or not. If the fields on your form are textboxes,
for example, and the user leaves them blank and submits the form, the fields
will exist in the action page but will have empty strings as values.

So, if you want to test for that instead, you could do something like this:

<cfif Len(Trim(Form.qty1)) and Len(Trim(Form.uc1))>
        <cfset tc1 = Form.qty1 * Form.uc1>
</cfif>

If there's the possibility that the fields may not exist as well, you could
add that to your test:

<cfif IsDefined("Form.qty1") and IsDefined("Form.uc1") and
Len(Trim(Form.qty1)) and Len(Trim(Form.uc1))>
        <cfset tc1 = Form.qty1 * Form.uc1>
</cfif>

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

----------------------------------------------------------------------------
--
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to