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

Help Needed for Custom Javascript Calculations Product Order Form

New Here ,
Jun 27, 2022 Jun 27, 2022

Copy link to clipboard

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

838

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

correct answers 1 Correct answer

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.

Votes

Translate

Translate
Community Expert ,
Jun 27, 2022 Jun 27, 2022

Copy link to clipboard

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.

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

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

Votes

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

Copy link to clipboard

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.

Votes

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

Copy link to clipboard

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).

Votes

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

Copy link to clipboard

Copied

I think it's only available on App store.

https://pdfexpert.com/ 

Votes

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

Copy link to clipboard

Copied

LATEST

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

Votes

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