Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiplying variables 1

Status
Not open for further replies.

leadman

Programmer
Joined
Jun 11, 2001
Messages
177
Location
US
Im trying to multiply variables to get a total but its throwing an error. i need the two cart variables to be multiplied first and then added to 'cartweight'. The following works fine but doesnt include the quantity of each item (session.cart[4]):
<cfset cartweight = cartweight + #session.cart[5]#>

but this doesnt work:
<cfset cartweight = cartweight + #session.cart[5]# * #session.cart[4]>

neither does this:
<cfset cartweight = cartweight + (#session.cart[5]# * #session.cart[4])>

or this:
<cfset cartweight = cartweight + ((#session.cart[5]#) * (#session.cart[4])>

the error is this :
Just in time compilation error

Invalid parser construct found on line 7 at position 76. ColdFusion was looking at the following text:
> (or &quot;)&quot;, depending on which of the above i tried)
Invalid expression format. The usual cause is an error in the expression structure.

any ideas?
 
Hi! Don't you need another # after #session.cart[4])>
in the examples above?

In other words:
not this:
<cfset cartweight = cartweight + (#session.cart[5]# * #session.cart[4])>

use this:
<cfset cartweight = cartweight + (#session.cart[5]# * #session.cart[4]#)>



;-)



 
Actually you don't need the # signs at all in a cfset statement unless it is in quotes. I noticed on the second one that you are missing the end parenthesis.

Try:
<cfset cartweight = cartweight + ((session.cart[5]) * (session.cart[4]))>


Regards,
Tim P.
 
If all else fails try:
<cfset cartweightNew = cartweight + (#session.cart[5]# * #session.cart[4]#)>
DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top