Skip to main content
Participating Frequently
June 27, 2025
Answered

Calculating half of a summed field using a checkbox

  • June 27, 2025
  • 1 reply
  • 601 views

I am working on a form that uses multiple text fields to calculate a total field that I need to then have divided by half using a checkbox.  I am able to get the total of all the fields, but when I add the check the checkbox it will not divide the total.

 

 

Correct answer Thom Parker

This type of functionality requires the use of a script. 

Do you want the existing total field to show half when the checkbox is checked (and the full total when unchecked)? or is the total half shown in a different field? 

 

If the half value is to be shown in the total field, then the total will need to be caluclated with a custom script, rather then the built-in "Sum" calculation.  To do this we'll need to know the names the fields to be summed and the checkbox, but just for the sake of writing a scirpt lets say the text boxes are "Text1" and "Text2", and the checkbox is "Check1"

 

// Custom calculation script for total field
var nSum = this.getField("Text1").value + this.getField("Text2").value;
if(this.getField("Checkd1").value == "Off"){
  // Checkbox is unchecked, so show the full total
  event.value = nSum;
}
else{
  // Checkbox is check, so divide in two. 
  event.value = nSum/2;
}

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
June 27, 2025

This type of functionality requires the use of a script. 

Do you want the existing total field to show half when the checkbox is checked (and the full total when unchecked)? or is the total half shown in a different field? 

 

If the half value is to be shown in the total field, then the total will need to be caluclated with a custom script, rather then the built-in "Sum" calculation.  To do this we'll need to know the names the fields to be summed and the checkbox, but just for the sake of writing a scirpt lets say the text boxes are "Text1" and "Text2", and the checkbox is "Check1"

 

// Custom calculation script for total field
var nSum = this.getField("Text1").value + this.getField("Text2").value;
if(this.getField("Checkd1").value == "Off"){
  // Checkbox is unchecked, so show the full total
  event.value = nSum;
}
else{
  // Checkbox is check, so divide in two. 
  event.value = nSum/2;
}

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
June 27, 2025

This worked perfectly!  Thank you so much!