• Global community
• Language:
• Deutsch
• English
• Español
• Français
• Português
• 日本語コミュニティ
Dedicated community for Japanese speakers
• 한국 커뮤니티
Dedicated community for Korean speakers
Exit
• Help Needed for Custom Javascript Calculations Pro...

Help Needed for Custom Javascript Calculations Product Order Form

New Here ,
Jun 27, 2022 Jun 27, 2022

Copied

Trying to get a total sum based on a particular variable in the backend of my javascript calculations on an product order form.

So on a product order form, there's a text field for quantity (no. of panels) and a checkbox (with the base price added to it).

When the checkbox is selected, the standard base price is added in the format properties (£300) and appears in one of the 'total' textfields. However the part I'm having difficulty with is having the quantity number determining what the total sum is based on a specific additional price(s).

Example: The aluminium base is £300.00 when checked. When the quantity for no. of panels is set to 2, the number should remain the same at £300. When the quantity is 3 panels, this needs to add an additional £40.00, totalling £340.00. If 4 is entered for the number of panels, that should add another £80.00 on top of it (total being £380.00), if 5 is typed into the quantity box, £120.00 needs to be added to the £300, totalling £420.00) and so on.

Aluminim base checkbox is "AluBase" while the quantity textfield is "NoPanels".

Now how do I create the correct javascript custom calculation/simplified field notion calculation to achieve this?

TOPICS
Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF forms

Views

491

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 Expert , Jun 27, 2022 Jun 27, 2022

As custom calculation script where you want to calculate total use this:

var v1 = Number(this.getField("NoPanels").valueAsString);
var check = this.getField("AluBase").valueAsString;
var cPrice = "";
var str = [
{qty: 1, Price:300},
{qty: 2, Price:300},
{qty: 3, Price:340},
{qty: 4, Price:380},
{qty: 5, Price:420}];
for(var i in str){
if(v1 == str[i].qty && check != "Off")
cPrice = str[i].Price;}
event.value = cPrice;

You can easily add more quantity and prices.

7 Replies 7
Community Expert ,
Jun 27, 2022 Jun 27, 2022

Copied

As custom calculation script where you want to calculate total use this:

var v1 = Number(this.getField("NoPanels").valueAsString);
var check = this.getField("AluBase").valueAsString;
var cPrice = "";
var str = [
{qty: 1, Price:300},
{qty: 2, Price:300},
{qty: 3, Price:340},
{qty: 4, Price:380},
{qty: 5, Price:420}];
for(var i in str){
if(v1 == str[i].qty && check != "Off")
cPrice = str[i].Price;}
event.value = cPrice;

You can easily add more quantity and prices.

Report

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

Copied

Amazing, this has worked perfectly, especially where I needed to edit the price. Thank you so much!

Report

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

Copied

Hey Nesa,

I'm trying to get the custom calculation to work also on iPad/Tablet but it doesn't seem to be working/displaying. Works fine on desktop though. Any ideas?

Kind regards

John

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 Expert ,
Jun 29, 2022 Jun 29, 2022

Copied

There's no real solution to this issue. Almost no scripts will work on a mobile device, at least not if you use Acrobat, unfortunately. Give PDF Expert by Readdle a go. It has better support for scripts in PDF files than Adobe's own software.

Report

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

Copied

Hi try67, that's deeply unfortunate. I'm surprised Adobe haven't done much in this area of functionality on tablets/mobiles.

Which of the PDF readers do I try? Can't pinpoint which one via Google Play is by Readdle (screenshot attached).

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 Expert ,
Jun 29, 2022 Jun 29, 2022

Copied

I think it's only available on App store.

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 Expert ,
Jun 29, 2022 Jun 29, 2022

Copied

LATEST

It's only available for iOS devices, I believe.