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

Need Calculation script Help

New Here ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

Hi 

 

I have 15 fields in my form with different amounts and checkboxes.

 

I need help in such a way like when I check to mark the boxes it only counts the amount of all checked boxes and skips the sum of unchecked boxes.

 

Please I need your kind help is there any posibility.

 

 

TOPICS
Create PDFs , How to , JavaScript , PDF forms

Views

170

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

Copy link to clipboard

Copied

Hi,

 

I would add a Document level JavaScript function something like :

( to add a Document level script, search the tools for "Document" and click "Document JavaScripts" then click add

function addToTotal ( number){
    addSubtractTotal ( number, true);
}

function subtractFromTotal ( number) {
    addSubtractTotal ( number, false);
}

function addSubtractTotal ( number, bAdd){
    var totalField = this.getField("TotalField");
    if ( bAdd){
        totalField.value += number;
    } else {
        totalField.value -= number;
    }
}

then on the mouse up action of each checkbox you can call the correct function depending on whether it is being checked or unchecked.

if  (event.target.value == "Yes") {
    addToTotal ( 15);
} else {
    subtractFromTotal ( 15);
}

 

NOTE: you will need to alter the names of field in this piece of code : this.getField("TotalField");

AND update the amount you want it to go up by

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

Copy link to clipboard

Copied

LATEST

You don't need script for this, set checkbox export value to be price for that item, then in total field go to calculate tab, select 'Value is the' leave it as 'sum+' and 'pick' checkboxes.

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