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?
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.
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.
Copy link to clipboard
Copied
Amazing, this has worked perfectly, especially where I needed to edit the price. Thank you so much!
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
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I think it's only available on App store.
Copy link to clipboard
Copied
It's only available for iOS devices, I believe.