Copy link to clipboard
Copied
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 = "";
}
Copy link to clipboard
Copied
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) {
Copy link to clipboard
Copied
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 = "";
}
Copy link to clipboard
Copied
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.)?
Copy link to clipboard
Copied
Hi there
I've just turned on the JS Console and ran the debugger, it's showing a lot of a TypeError messages but I can't really understand it to be honest. I would love to the share the document if you were able to help I would most appreciate it. It's very frustrating!!!!
I have loaded the document on Google Drive:
https://drive.google.com/open?id=1jIQ633Q_aXxTdZCLY1UD8xLo_IceBogE
https://drive.google.com/open?id=1jIQ633Q_aXxTdZCLY1UD8xLo_IceBogE
I have only set the column Question 1, Client 1 a) - f) but it needs to sum total in the bottom box. If I can get this to work I can do the rest of the questions in the same manner.
Another issue I have is that I can't get the 'value' text field to disappear once you have clicked on it but have deselected all checkboxes but I can deal with this issue if it calculates correctly.
Many thanks
Kelly
Copy link to clipboard
Copied
getField("Q1 Client 1#0") returns null
Do access the values of the checkbox you must use getField("Q1 Client 1").value
Copy link to clipboard
Copied
Hi there, thanks for your help however this won't work either as adds up all fields rather than just the visible 'checked' field. The 5 check boxes (different answers for the same question with different scores) use the same name but different export value so only one can be selected at a time. Maybe this is where the problem lies? Thanks
Copy link to clipboard
Copied
There are issues with the code, but also with the implementation of this task.
Why are the text fields editable and visible in the first place? Do you want to allow the user to be able to manually edit them?
If not, then you should remove them. The scores are already present on the right so the user can see them there.
All you need to do is apply them as the export values of the check-boxes, and then you'll be able to add them up directly.
Copy link to clipboard
Copied
Yes thought that was the case, I was going to lock them once finished but didn't realise that the export value would do same job so thank you, will give it a go now!
Copy link to clipboard
Copied
You can access the widgets of the checkboxes with:
getField("Q1 Client 1.0")
getField("Q1 Client 1.1")
and so on
Copy link to clipboard
Copied
Thanks also for widget help, didn't know this either!! Much appreciated