5 Replies Latest reply on Sep 15, 2014 5:10 AM by Test Screen Name

# conditional grand total...stuck

Hello,

Would really really appreciate some help with this as I am somewhat stuck.

I have an order form with individual products, packages and a grand total. The grand total needs to be discounted by either nothing, 5% (if 2 packages are selected) or 10% (if three or more packages are selected).

I may be over complicating things but what I have done so far is to create two hidden text boxes to make the calculation easier.

1) a box called "GRAND1" which adds up the quantities of the packages

2) a box called "GRAND2" which is a hidden grand total adding up all the subtotals

Finally there is a box called "GRAND" which is the visible grand total box. I thought it might be easier to do it in this way but feel free to correct me.

As it stand the code I am working with is:

var x = this.getField("GRAND2").value;

var y = this.getField("GRAND1");

if( y = 2 ) event.value = x / 1.05;

else if( y >= 3 ) event.value = x / 1.10;

else if( y < 2 ) event.value = x / 1;

I'd love some help as I really have no idea what I am doing...sorry and thanks in advance

• ###### 1. Re: conditional grand total...stuck

Use:

var y = this.getField("GRAND1").value;

• ###### 2. Re: conditional grand total...stuck

Thanks for the very quick response!

I've added the code you suggested but unfortunately this doesn't seem to work. The code is now:

var x = this.getField("GRAND2").value;

var y = this.getField("GRAND1").value;

if( y = 2 ) event.value = x / 1.05;

else if( y >= 3 ) event.value = x / 1.10;

else if( y < 2 ) event.value = x / 1;

Problem is that no matter what the package quantity ("GRAND1" or y) is the grand total is always divided by 1.05. It seems to ignore everything else and just divide by 1.05????

Any ideas?

Thanks again for the quick reply.

• ###### 3. Re: conditional grand total...stuck

Use this:

if( y == 2 ) event.value = x / 1.05;

• ###### 4. Re: conditional grand total...stuck

All working now!

Thanks a lot, you are a legend!

• ###### 5. Re: conditional grand total...stuck

In general, beware of if ( something = somethingelse )

The = isn't an error because it means something but it doesn't mean what you think.

You must use == .

It's a serious trap, and it catches us all now and again.