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

Prepare Form Calculations

New Here ,
Mar 14, 2023 Mar 14, 2023

Copy link to clipboard

Copied

While I have familuarised myself with using the "Prepare a Form" system, to get to the stage of having an editable document, I am now trying to go one step further to have it auto calculate.

 

To give a bit of context, the fields on the left are product descriptions, while the boxes highlighted in red are the service costs and the boxes highlighted in blue are whether the services (and associated costs) are selected for use.

 

I am trying to work out how (assuming it is possible) to calculate into the green box the value from the red boxes, where the relative blue fields have been selected.

 

I did consider looking to give the blue fields the same value as the red but these values will be different from document to document.

 

The Mission: from a really simplistic point of view I have been trying to establish if a selected blue box can pull the value from red and subsequently if the green box can pull an all-in cost.

 

Is anyone able to offer up any advise on this?

 

 

Screenshot 2023-03-14 at 09.07.19.png

TOPICS
Create PDFs , Edit and convert PDFs , PDF forms

Views

1.1K

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 ,
Mar 14, 2023 Mar 14, 2023

Copy link to clipboard

Copied

Hi,

This could be done by creating a document level javascript like the one below:

 

// this function takes the checkbox event (when it is checked or unchecked)
// and the value from the field next to it
// if the checkbox is checked it adds the value to the total field
// if it is unchecked it subtracts the value.
function updateTotal( eventField, valueToAdd)
{
    var totalVar = this.getField("Total");
    eventField.isBoxChecked(0) ? totalVar.value += valueToAdd : totalVar.value -= valueToAdd;
}

 

Then for each check box you need to add the javascript below to the "Mouse Up"Action

 

// this calls the other function, with the checkbox that was clicked
// and the value from the text field( needs to be changed for each row)
updateTotal ( event.target, this.getField("Upfront_1").value);

 

 

I have also attached a sample file that shows how it works.

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 ,
Mar 14, 2023 Mar 14, 2023

Copy link to clipboard

Copied

LATEST

Thank you not only for the reply but the speed of your reply!

 

I have updated all fields to be named appropriately and added in the 2x javascripts that you have provided.

 

Initally these were adding a value of "1" for every checkbox selection but having tried to fix this there is now nothing being added.

 

I have screen shot an example of how I have formatted the checkboxes and also how I have added the code to the "Total" box.

 

Is there anything obvious I have got wrong and need to amend for this to work?

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 ,
Mar 14, 2023 Mar 14, 2023

Copy link to clipboard

Copied

If your fields are named Upfront_1-26 and Check Box1-26 you can use this as custom calculation script of 'Green' field:

var total = 0;
for( var i=1; i<=26; i++){
if(this.getField("Upfront_"+i).valueAsString != "" && this.getField("Check Box"+i).valueAsString != "Off")
total += Number(this.getField("Upfront_"+i).valueAsString)};
event.value = total;

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