Skip to main content
Participating Frequently
Jul 1, 2019 9:43 AM UTC
Question

custom calculation for only visible fields to calculate?

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 is closed to new replies. Start a new post to keep the conversation going.

10 replies

try67
Community Expert
Community Expert
Jul 1, 2019 10:07 AM UTC

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) {

Translate
Participating Frequently
Jul 1, 2019 11:23 AM UTC

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 = "";

}

Translate
try67
Community Expert
Community Expert
Jul 1, 2019 11:42 AM UTC

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.)?

Translate