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

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

New Here ,
Mar 17, 2017 Mar 17, 2017

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;

TOPICS
Acrobat SDK and JavaScript
812
Translate
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

correct answers 1 Correct answer

LEGEND , Mar 17, 2017 Mar 17, 2017

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

...
Translate
Community Expert ,
Mar 17, 2017 Mar 17, 2017

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

Translate
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
New Here ,
Mar 17, 2017 Mar 17, 2017

3:Field:Calculate

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

Translate
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
New Here ,
Mar 17, 2017 Mar 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++;

Translate
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
LEGEND ,
Mar 17, 2017 Mar 17, 2017

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.

Translate
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
New Here ,
Mar 20, 2017 Mar 20, 2017

This is the entire error

SyntaxError: unterminated string literal

7:

SyntaxError: unterminated string literal

7:

SyntaxError: unterminated string literal

7:

SyntaxError: unterminated string literal

7:

SyntaxError: unterminated string literal

7:

SyntaxError: unterminated string literal

7:

SyntaxError: unterminated string literal

7:

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

3:Field:Calculate

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

3:AcroForm:Text3:Calculate

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

3:AcroForm:Text3:Calculate

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

3:AcroForm:Text3:Calculate

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

3:AcroForm:Text3:Calculate

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

3:AcroForm:Text3:Calculate

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

3:AcroForm:Text3:Calculate

Translate
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
New Here ,
Mar 20, 2017 Mar 20, 2017
LATEST

OH! nevermind i figured it out I had one named NA instead of Na. Thanks so much for the help!!!

Translate
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