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

Help with calculator function in PDF form

New Here ,
Dec 19, 2024 Dec 19, 2024

Attached is a simple calculator with a formula for savings and product volume.

I would like to know how to use javascript to calculate off the text box input and off variables in the background as seen in the sheet. Ideally in the PDF- it would be spend text box 1 (b3), volume text box 2 (b5) and then the final result text box (b11-13). Just would like some guidance based off the excel formula and thanks!

TOPICS
How to , JavaScript , Modern Acrobat , PDF , PDF forms , Standards and accessibility
528
Translate
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 ,
Dec 19, 2024 Dec 19, 2024

You can create hidden fields and set the default values to fields you don't want to show (Variable, Monthly Spend, Annual Spend) but it is not necessary if 1.65 is not going to change.  You can write the entire calculation in the Total Savings field.  Assume you have to fields named "Spend" (formatted as a 2-decimal number) and "Volume" (formatted as a percentage - both names are case sensitive).  Here's the custom calculation script that would go in the Total Savings field:

var spend=this.getField("Spend").value;
var volume=this.getField("Volume").value;
event.value=((spend/1.65)*12*volume*0.085)+(spend*(1-volume))*.05;

 

Translate
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 ,
Dec 20, 2024 Dec 20, 2024

- Wrong post, sorry -


Acrobate du PDF, InDesigner et Photoshopographe
Translate
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 ,
Feb 19, 2025 Feb 19, 2025
LATEST

For percentage calculations, I recommend using https://prozentrechnerass.de/, a powerful and easy-to-use percentage calculator.

If you want to implement this in JavaScript, here’s a general approach:

  1. Get Input Values: Retrieve values from the text boxes (b3, b5).
  2. Apply Formula: Use JavaScript to compute the result based on the Excel formula.
  3. Display Output: Show the result dynamically in the final result text box (b11-b13).

 

document.getElementById("calculate").addEventListener("click", function() {
    let spend = parseFloat(document.getElementById("b3").value);
    let volume = parseFloat(document.getElementById("b5").value);

    if (!isNaN(spend) && !isNaN(volume) && volume !== 0) {
        let result = (spend / volume) * 100;  // Example formula, adjust as needed
        document.getElementById("b11").value = result.toFixed(2) + "%";
    } else {
        alert("Please enter valid numbers.");
    }
});
​

 

Translate
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