Copy link to clipboard
Copied
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;
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;
...Copy link to clipboard
Copied
Check the JS Console (Ctrl/Cmd+J) for errors.
Copy link to clipboard
Copied
3:Field:Calculate
TypeError: this.getField(...) is null
Copy link to clipboard
Copied
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++;
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
OH! nevermind i figured it out I had one named NA instead of Na. Thanks so much for the help!!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now