Skip to main content
rae333
Participant
March 17, 2017
Answered

Finding the sum of the amount of checkboxes checked. Only 2 columns work.

  • March 17, 2017
  • 1 reply
  • 894 views

I have a form with a bunch of questions and then options Yes, No, NA. You can select a checkbox under each answer and then at the bottom i have a box that totals each column into "#Yes" "#no" "#NA". I have used the same script in ALL THREE boxes but only 2 (Yes and No) work. The NA column shows no number total.

var total = 0;

for (var i=1; i<=20; i++) {

if (this.getField("Yes"+i).value!="Off") total++;

}

event.value = total;

var total = 0;

for (var i=1; i<=20; i++) {

if (this.getField("No"+i).value!="Off") total++;

}

event.value = total;

var total = 0;

for (var i=1; i<=20; i++) {

if (this.getField("Na"+i).value!="Off") total++;

}

event.value = total;

This topic has been closed for replies.
Correct answer gkaiseril

That error message is telling you that there is no field with name you are looking for. You may need to add some additional code to test for a retuned value of "null" for the field object your are trying to access.

var total = 0;

var oField; // variable for the field object;

for (var i=1; i<=20; i++) {

oField = this.getField("Na" + i);

if(oField == null)

{

app.alert("Could not fine field 'Na"" + I, 1,0);

} else{

if (oField.value != "Off") total++;

} //

}

event.value = total;

See Acrobat JavaScript API Reference getField.

The above assumes your error is for the total of the NA check boxes. It is hard to tell what calculation is causing the error since the entire error message was not posted.

1 reply

try67
Community Expert
Community Expert
March 17, 2017

Check the JS Console (Ctrl/Cmd+J) for errors.

rae333
rae333Author
Participant
March 17, 2017

3:Field:Calculate

TypeError: this.getField(...) is null

rae333
rae333Author
Participant
March 17, 2017

I thought this mean that im asking for a field that doesnt exist but all my fields are Na1, Na2... and I am using if (this.getField("Na"+i).value!="Off") total++;