Need help with javascript calculations for Acrobat

New Here ,
May 26, 2022 May 26, 2022

Copy link to clipboard

Copied

Here is what I am trying to accomplish for fillable Acrobat form:

(FieldAQty*125)+ (FieldBQty*25) = (field C)

(FieldAQty*125) is Field A multiplied by price
(FieldBQty*25) is Field A multiplied by price
(filed C) is the sum of Field A & B

 

Here is javascript I created, but it is not calculating.

((this.getField("BannerQty1").value*175))+((this.getField("WindowClingQty1").value*25))+((this.getField("CounterCardQty1").value*40))+((this.getField("AcrylicWallDisplayQty1").value*180))+((this.getField("CrystalStyleAwardQty1").value*195))

TOPICS
How to , JavaScript , PDF forms

Views

97

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 26, 2022 May 26, 2022

Copy link to clipboard

Copied

Check the Javascript console for errors.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 27, 2022 May 27, 2022

Copy link to clipboard

Copied

Your code seems fine to me (unless you misspelled a field's name), although it doesn't really match what you described... So the main issue is you're not applying it back to the field. Before all of it add the following:

event.value =

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 27, 2022 May 27, 2022

Copy link to clipboard

Copied

Try67: That was it! Thanks so much!

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 27, 2022 May 27, 2022

Copy link to clipboard

Copied

Need more help! Here is code for shipping that worked, however my shipping manager just threw me a curve ball:

 

If customer orders more than 1 for Window Cling, they only add $1 per additonal item.

Qty 2, shipping is $9+1

Qty 3, shipping is $9+2

 

event.value =((this.getField("WallPlaqueQty1").value*22))+((this.getField("FrameQty1").value*35))+((this.getField("CounterCardQty1").value*11))+((this.getField("CrystalAwardQty1").value*24))+((this.getField("BannerQty1").value*35))+((this.getField("WindowClingQty1").value*9))+((this.getField("BOshowcaseQty1").value*81));

 

So I figured if I used the value of $8 and added the qty then it would work...8+1, 8+2, etc

Here is code I tried but it there is an error in it. I think its in the last part where I tried to add the Qty of products after the shipping value

 

event.value =((this.getField("WindowClingQty1").value+8+((this.getField("WindowClingQty1”));

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 27, 2022 May 27, 2022

Copy link to clipboard

Copied

Multiple issues there:

-You have to only use straight quotes in your code, not curly ones.

-You forgot the .value part after the second field.

-Your opening and closing brackets don't match. You don't need to add that many, actually.

 

Also, it's a good idea to convert the values to number explicitly, or they might be treated as strings.

So use this code:

 

 

event.value = Number(this.getField("WindowClingQty1").value)+8+Number(this.getField("WindowClingQty1").value);

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

So why in the first forumla are there (( before& after each line item , but then in this last code there is only 1?

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

I don't know, you provided the code... But it's not necessary.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

OK, The top code below works but not exactly what I need. Line item 2 & 3 are adding additional values to the other lines...

So I need them to only add if there is a value added in their repective quantity.

 

For Example (Forumula below)  if I order 2 banners, the shipping is totalling $88, instead of $70

 

Shipping

Banners - $35

Window Cling - $9 (+1 for each additional over 1)

Counter Card - $11 (+1 for each additional over 1)

Acrylic Wall Display - $22

Crystal Style Award - $24

 

event.value = Number(this.getField("BannerQty1").value*35)+Number(this.getField("WindowClingQty1").value)+8+Number(this.getField("CounterCardQty1").value)+10+Number(this.getField("AcrylicWallDisplayQty1").value*22)+Number(this.getField("CrystalStyleAwardQty1").value*2;

 

I tried seperating each line item by adding (( )) before & after each one, however this new code is not working. Error says is is missing paraenthetical at line 2:

 

event.value =((Number(this.getField("BannerQty1").value*35))+((Number(this.getField("WindowClingQty1").value+8))+((Number(this.getField("CounterCardQty1").value+10))+((Number(this.getField("AcrylicWallDisplayQty1").value*22))+((Number(this.getField("CrystalStyleAwardQty1").value*24));

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

You don't have always ) after value.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

Like this?

 

event.value = Number(this.getField("BannerQty1").value)*35)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

Like this:

event.value = Number(this.getField("BannerQty1").value)*35

 

The number of ( must match the number of )

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

I tried both of these (and both caluclate), however both are adding the +8 and +10 value to grand total, even with there are no quantites in those line items...Line items 2 & 3.

 

The +8 value and +10 value should only be calculated if there is a qty value in the number field.

 

event.value = ((Number(this.getField("BannerQty1").value)*35))+((Number(this.getField("WindowClingQty1").value)+8))+((Number(this.getField("CounterCardQty1").value)+10))+((Number(this.getField("AcrylicWallDisplayQty1").value)*22))+((Number(this.getField("CrystalStyleAwardQty1").value)*24));


event.value = Number(this.getField("BannerQty1").value*35)+Number(this.getField("WindowClingQty1").value)+8+Number(this.getField("CounterCardQty1").value)+10+Number(this.getField("AcrylicWallDisplayQty1").value*22)+Number(this.getField("CrystalStyleAwardQty1").value*24);

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

LATEST

You have to use conditional statements for that, then. Something like this:

 

event.value = Number(this.getField("BannerQty1").value)*35;
if (Number(this.getField("WindowClingQty1").value)!=0)
	event.value+=Number(this.getField("WindowClingQty1").value)+8;

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines