Skip to main content
norml65859813
Participating Frequently
January 23, 2021
Question

I have a rather complex checkbox issue, I've never wrote JavaScript before so can really use help

  • January 23, 2021
  • 2 replies
  • 1769 views

I have a a fillable pdf that has 3 groups of six checkboxes

The sheet is for bidding projects with minority contractors

African American, Asian American, Native America, Woman, Hispanic, Disabled

I need to calculate the sums based on a checkbox along the appropriate catergory 

I started putting this together but not sure have to apply it to the Totals at the bottom...

 

var checkbox1Value = this.getField("AfricanAmerican_1");
if (checkbox1Value.isBoxChecked(0))
var checkbox1Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox1Value = 0

var checkbox2Value = this.getField("AfricanAmerican_2");
if (checkbox2Value.isBoxChecked(0))
var checkbox2Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox2Value = 0

var checkbox3Value = this.getField("AfricanAmerican_3");
if (checkbox3Value.isBoxChecked(0))
var checkbox3Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9

else
var checkbox3Value = 0

var checkbox4Value = this.getField("AsianAmerican_1");
if (checkbox4Value.isBoxChecked(0))
var checkbox4Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox4Value = 0

var checkbox5Value = this.getField("AsianAmerican_2");
if (checkbox5Value.isBoxChecked(0))
var checkbox5Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox5Value = 0

var checkbox6Value = this.getField("AsianAmerican_3");
if (checkbox6Value.isBoxChecked(0))
var checkbox6Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9

else
var checkbox6Value = 0

 

var checkbox7Value = this.getField("NativeAmerican_1");
if (checkbox7Value.isBoxChecked(0))
var checkbox7Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9

else
var checkbox7Value = 0

var checkbox8Value = this.getField("NativeAmerican_2");
if (checkbox8Value.isBoxChecked(0))
var checkbox8Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox8Value = 0

var checkbox9Value = this.getField("NativeAmerican_3");
if (checkbox9Value.isBoxChecked(0))
var checkbox9Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox9Value = 0

var checkbox10Value = this.getField("Women_1");
if (checkbox10Value.isBoxChecked(0))
var checkbox10Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9

else
var checkbox10Value = 0

 

var checkbox11Value = this.getField("Women_2");
if (checkbox11Value.isBoxChecked(0))
var checkbox11Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox11Value = 0

var checkbox12Value = this.getField("Women_3");
if (checkbox12Value.isBoxChecked(0))
var checkbox12Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox12Value = 0

var checkbox13Value = this.getField("Hispanic_1");
if (checkbox13Value.isBoxChecked(0))
var checkbox13Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9

else
var checkbox13Value = 0

var checkbox14Value = this.getField("Hispanic_2");
if (checkbox14Value.isBoxChecked(0))
var checkbox14Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox14Value = 0

var checkbox15Value = this.getField("Hispanic_3");
if (checkbox15Value.isBoxChecked(0))
var checkbox15Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox15Value = 0

var checkbox16Value = this.getField("Disabled_1");
if (checkbox16Value.isBoxChecked(0))
var checkbox16Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9

else
var checkbox16Value = 0

var checkbox17Value = this.getField("Disabled_2");
if (checkbox17Value.isBoxChecked(0))
var checkbox17Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox17Value = 0

var checkbox18Value = this.getField("Disabled_3");
if (checkbox18Value.isBoxChecked(0))
var checkbox18Value = PartAmt1+ PartAmt2+ PartAmt3+ PartAmt4+ PartAmt5+ PartAmt6+ PartAmt7+ PartAmt8+ PartAmt9
else
var checkbox18Value =

 

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
January 27, 2021

Just in general, tt's best to start small and work your way up. You need to solve the problem of doing a simple conditional calculation with check boxes first, before creating this large script.  There are lots of details about scripting you have to learn.

 

You can read about calculations and form scripting at these links:

https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations/

https://acrobatusers.com/tutorials/conditional-execution/

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
January 23, 2021

Generally speaking, to apply a value to a calculated field you would use event.value at the end of your code, like this:

event.value = 10;

Or it can be a variable, like this:

event.value = result;

norml65859813
Participating Frequently
January 24, 2021

not sure I understand, are you saying to add that at the end of every event I have, or just at the very end, or instead of what I have???  I do appreciate the input, so don't give up on me, as mentioned I'm just starting the JAVA ride... I did create the same sheet in Excel and did manage to get all the calculation working I just wish when you save an Excel sheet as a pdf it would include the calculation, then life would be easy 🙂

try67
Community Expert
Community Expert
January 24, 2021

First of all, it's JavaScript, not Java. A small but important difference.

In closer inspection your code is not very clear. Can you explain how exactly it is supposed to work?