Skip to main content
New Participant
December 3, 2022
Answered

Calculation resulting from checkbox selection in a PDF

  • December 3, 2022
  • 2 replies
  • 1060 views

I am very new at creating custom calculation scripts, and I don't know how to do the following:

I need to calulate the total of all fees associated with the boxes checked:

    

The checkboxes are titled Checkbox1, Checkbox2, etc.

The exception is the custom fee boxes, that's where I'm getting stuck. If those checkboxes are clicked, they will enter a dollar amount in the FEE1-FEE3 fields.

The Total will be calculated in a "Total Fees" field.

Is this possible?

Thank you VERY much for your help!

    This topic has been closed for replies.
    Correct answer try67

    You can do it using this code (I assumed the names of the check-boxes are Checkbox1 to Checkbox10):

     

    var total = 0;
    for (var i=1; i<=7; i++) {
    	var v = this.getField("Checkbox"+i).valueAsString;
    	if (v!="Off") total+=Number(v);
    }
    if (this.getField("Checkbox8").valueAsString!="Off") total+=Number(this.getField("FEE1").valueAsString);
    if (this.getField("Checkbox9").valueAsString!="Off") total+=Number(this.getField("FEE2").valueAsString);
    if (this.getField("Checkbox10").valueAsString!="Off") total+=Number(this.getField("FEE3").valueAsString);
    event.value = total;

     

    In order for it to work, though, you must set the export values of the first 7 check-boxes as the price for that item (without the dollar symbol, just as a number).

    2 replies

    try67
    try67Correct answer
    Community Expert
    December 3, 2022

    You can do it using this code (I assumed the names of the check-boxes are Checkbox1 to Checkbox10):

     

    var total = 0;
    for (var i=1; i<=7; i++) {
    	var v = this.getField("Checkbox"+i).valueAsString;
    	if (v!="Off") total+=Number(v);
    }
    if (this.getField("Checkbox8").valueAsString!="Off") total+=Number(this.getField("FEE1").valueAsString);
    if (this.getField("Checkbox9").valueAsString!="Off") total+=Number(this.getField("FEE2").valueAsString);
    if (this.getField("Checkbox10").valueAsString!="Off") total+=Number(this.getField("FEE3").valueAsString);
    event.value = total;

     

    In order for it to work, though, you must set the export values of the first 7 check-boxes as the price for that item (without the dollar symbol, just as a number).

    New Participant
    December 4, 2022

    Thank you VERY much Try67 - that worked perfectly! I've seen your other replies - you are such a blessing to this community, I appreciate you!

    kglad
    Community Expert
    December 3, 2022

    in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

     

    <moved from using the community>