Planet PDF Forum Archive

Planet PDF ForumWowsers! This is page is old, head to the LIVE Planet PDF Forum. It features more than 10 conferences, covering everything from beginner to in-depth developer and pre-press discussions. If you wish to continue... one & two archive covers 1999-2011 (160,000 pages).


New Forum | Previous | Next | (P-PDF) Beginners


Topic: Re: javascript FINALLY but... (Via Email)
Conf: (P-PDF) Beginners, Msg: 119572
From: prodok
Date: 10/4/2004 03:47 AM

I don't assign it to any level of blondeness . As is, things should
work.

However, the code is way too complicated, because there are nested
if...else statements, which make things a lot easier. And there are a
few minor mistakes which apparently have no effect.

A possible simplified version would be the following, placed in the
Calculate event of the amtdisc field (note that this is important for
this code fragment; see below on how to integrate it into a bigger
calculation).

var v1 = this.getField("subtotal") ;
if (v1.value < 300) {
event.value = 0 ;
} else {
if (v1.value < 1000) {
event.value = 0.05 ;
} else {
event.value = 0.07 ;
}
}

and that should do exactly the same, and it would also not create any
undefined stuff if the subtotal were negative (where I assumed that the
discount would be 0 as well).

The key here is that the "is between" condition is not needed at least
after the first decision, because in order to reach that path, the
lower value condition is already fulfilled. In other words, in order to
be checked whether the value to be tested is less than 1000, it has
already not less than 300 etc.

Now, there are a few more things to watch out for. We are working with
numbers, and therefore, it is strongly recommended to create numbers.
What the original code did, was not creating numbers in the field
amtdisc, but text strings. This may lead to unpredictable results in
subsequent calculations.

Another thing is that it is good style to consolidate all calcualtions
into one single script. Assuming that there is somewhere a grand total,
and that there is also some calculation in the subtotal field, it would
be better to take all the calculations into a script which then either
gets assigned to the field for the grand total (if that is the last
result in such a chained calculation), or the final result in the
chained calculation, or (a third possibility, making use of the fact
that the Calculate event is triggered every time a field gets
committed), in another field, invisible and read-only, which is simply
there to hold the calculation.

In that case, you would use "this.getField("amtdisc").value instead of
event.value.

Hope, this can help.



Max Wyss
PRODOK Engineering
Low Paper workflows, Smart documents, PDF forms
CH-8906 Bonstetten, Switzerland

Fax: +41 1 700 20 37
or +1 815 425 6566
e-mail: mailto:max@prodok.com
http://www.prodok.com



[ Building Bridges for Information ]


______________________




> Sorry but I'm new at this, or too blonde to get it the first hundred
> times. Had my javascripts confused but didn't notice w3schools
> website telling me that. I finally got the following code to work:
>
> var v1 = this.getField("subtotal").value
> if(v1 >= 0 && v1 <= 299)
> {
> this.getField("amtdisc").value = "0";
> }
> else if(v1 >= 300 && v1 <= 999)
> {
> this.getField("amtdisc").value = ".05";
> }
> else if(v1 >= 1000)
> {
> this.getField("amtdisc").value = ".07";
> }
>
>
> What happens is
> If the subtotal field = 0 to $299 this field(amtdisc) should display 0,
> 300 to 999 display .05, 1000 or above display .07.
> It does that correctly but the next field "discount" should take the
> subtotal * amtdisc and display the $ result.
> ie.. $299(subtotal)*0 (amtdisc) displays $0(discount) or
> 300(subtotal)*05(amtdisc) display $15 (discount)
>
> The problem now comes when the subtotal = 0 to 299 or 301 to 999 or
> 1001 and up the (amtdisc) and (discount) fields are correct. But when
> the (subtotal) = 300 or 1000 it does not calculate.
>



PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link...

Download free demo

Debenu PDF Tools Pro

It's simple to use and will let you preview and edit PDF files, it's a Windows application that makes...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.