Skip to main content
Participating Frequently
July 1, 2019
Question

custom calculation for only visible fields to calculate?

  • July 1, 2019
  • 1 reply
  • 809 views

I have a Adobe acrobat questionaire which has different scores dependant on which of the 6 check boxes is checked I have set each individual score in a hidden text box which is made visible when the corresponding check box is selected. This works fine except I can't get only the visible score to show in a total field. It also calculates the hidden amounts. I have used the custom calculation java script below on the Total field but nothing shows, can anyone help me : (

// Custom calculation script for Total field

// Initialize variable

var sum = 0;

// Add first field value if its corresponding check box is selected

if (getField("Q1 Client 1#0").value !== "Off") {

    sum += +getField("Q1 a1").value;

}

// Add second field value if its corresponding check box is selected

if (getField("Q1 Client 1#1").value !== "Off") {

    sum += +getField("Q1 b1").value;

}

// Add third field value if its corresponding check box is selected

if (getField("Q1 Client 1#2").value !== "Off") {

    sum += +getField("Q1 c1").value;

}

// Add fourth field value if its corresponding check box is selected

if (getField("Q1 Client 1#3").value !== "Off") {

    sum += +getField("Q1 d1").value;

}

// Add fifth field value if its corresponding check box is selected

if (getField("Q1 Client 1#4").value !== "Off") {

    sum += +getField("Q1 e1").value;

}

// Add sixth field value if its corresponding check box is selected

if (getField("Q1 Client 1#5").value !== "Off") {

    sum += +getField("Q1 f1").value;

}

// Set this field value to the sum, or set to blank if zero

if (sum > 0) {

    event.value = sum;

} else {

    event.value = "";

}

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
July 1, 2019

Change these lines:

if (getField("Q1 Client 1#0").value !== "Off") {

To:

if (getField("Q1 Client 1#0").value !== "Off" && getField("Q1 Client 1#0").display==display.visible) {

Participating Frequently
July 1, 2019

Thanks so much, unfortunately I still can't get it to work and have checked all my field names, nothing whatsoever is calculating, maybe it has something to do with the way I used the show/hide field action to hide the buttons? Or something else in my settings? any other possible suggestions?

// Custom calculation script for Total field

// Initialize variable

var sum = 0;

// Add first field value if its corresponding check box is selected

if (getField("Q1 Client 1#0").value !== "Off" && getField("Q1 Client 1#0").display==display.visible) {

    sum += +getField("Q1 a1").value;

}

// Add second field value if its corresponding check box is selected

if (getField("Q1 Client 1#1").value !== "Off" && getField("Q1 Client 1#1").display==display.visible) {

    sum += +getField("Q1 b1").value;

}

// Add third field value if its corresponding check box is selected

if (getField("Q1 Client 1#2").value !== "Off" && getField("Q1 Client 1#2").display==display.visible) {

    sum += +getField("Q1 c1").value;

}

// Add fourth field value if its corresponding check box is selected

if (getField("Q1 Client 1#3").value !== "Off" && getField("Q1 Client 1#3").display==display.visible) {

    sum += +getField("Q1 d1").value;

}

// Add fifth field value if its corresponding check box is selected

if (getField("Q1 Client 1#4").value !== "Off" && getField("Q1 Client 1#4").display==display.visible) {

    sum += +getField("Q1 e1").value;

}

// Add sixth field value if its corresponding check box is selected

if (getField("Q1 Client 1#5").value !== "Off" && getField("Q1 Client 1#5").display==display.visible) {

    sum += +getField("Q1 f1").value;

}

// Set this field value to the sum, or set to blank if zero

if (sum > 0) {

    event.value = sum;

} else {

    event.value = "";

}

try67
Community Expert
Community Expert
July 1, 2019

Do you see any error messages in the JS Console?

If not, can you share the file with us (via Dropbox, Google Drive, Adobe Document Cloud, etc.)?