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

Java script needed to count form fields with text and ignore empty fields for Acrobat Pro

Community Beginner ,
Mar 27, 2024 Mar 27, 2024

Copy link to clipboard

Copied

Janelle354870978x5k_0-1711564003685.png

What is the Java script that is needed for box4 to reflect the count of the number of x's in the form fields box1, box2, box3 disregarding any the blank form fields? In this sample, the form fields are labeled box1, box2, box3, and box4 left to right.  

 

I have found the java script below but do not know where to substitute box1, box2, box3, and box4 or what will need to removed from this java script.

 

 

var total = "";

for (var i=1; i<=28; i++) {var f = Number(this.getField("Rating"+i).valueAsString);

if (f > 0 && f <= 4) total++;} event.value = total;

 

Thank you for your assistance!!

Janelle

TOPICS
How to , JavaScript , PDF forms

Views

149

Translate

Translate

Report

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

Community Beginner , Mar 27, 2024 Mar 27, 2024

Would it be correct to use

var total = 0; for(var i=5; i<=7; i++) { var f = this.getField("box"+i).valueAsString; if(f === "X") total++;} event.value = (total == 0) ? "" : total;

 

 

 

Votes

Translate

Translate
Community Expert ,
Mar 27, 2024 Mar 27, 2024

Copy link to clipboard

Copied

If the value is exactly "X" use this:

 

var total = 0;
for(var i=1; i<=4; i++) {
var f = this.getField("box"+i).valueAsString;
if(f === "X") total++;} 
event.value = (total == 0) ? "" : total;

 

Votes

Translate

Translate

Report

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
Community Beginner ,
Mar 27, 2024 Mar 27, 2024

Copy link to clipboard

Copied

Thank you! This script works well for a single row. Apparently, I have a lot to learn about Java script.

 

What would I do if I have a second row of boxes labeled box5, box6, box7 and box8 that require their own calculation of X to be shown in box8? Would I place two different Java scripts in box4 and box8's properties?

 

 

Votes

Translate

Translate

Report

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
Community Beginner ,
Mar 27, 2024 Mar 27, 2024

Copy link to clipboard

Copied

Would it be correct to use

var total = 0; for(var i=5; i<=7; i++) { var f = this.getField("box"+i).valueAsString; if(f === "X") total++;} event.value = (total == 0) ? "" : total;

 

 

 

Votes

Translate

Translate

Report

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
Community Expert ,
Mar 27, 2024 Mar 27, 2024

Copy link to clipboard

Copied

Yes, use another script for box 8, if you wish to show count in box 4 from (box1,box2 and box3) change 4 to 3 in the loop:

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

 

For box8 set loop like this:

for(var i=5; i<=7; i++) {

 

Everything else is the same.

 

 

Votes

Translate

Translate

Report

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
Community Beginner ,
Mar 27, 2024 Mar 27, 2024

Copy link to clipboard

Copied

LATEST

Thank you!!

Votes

Translate

Translate

Report

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