Copy link to clipboard
Copied
JavaScript Newbie here...
I am attempting to automate the attached scoring sheet. This is a Federal form, so I cannot change the format. I am using radio buttons for each question as only one choice can be selected. The first 3 fields have unique values assigned and that value varies based on the specific question. However, the 4th field "Did Not Occur" retains the same value as the "Good" field - either 3, 6, or 9 depending on the question. In an attempt to differenciate between the two fields, I gave the "Did Not Occur" fields values adding a .1.
I need to total the value of all questions with a score of "Did Not Occur" separately from the other scores, that number must be subtracted from the "Maximum Total Score" (192). I have added an "Adjusted Max Total Score" field for that number. Then, the Adjusted Max is used to calculate the "Percent Score."
Here are the calculation instructions from the manual:
TYIA!
Copy link to clipboard
Copied
Read these articles:
https://www.pdfscripting.com/public/How-to-Write-a-Basic-PDF-Calculation-Script.cfm
https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm
Copy link to clipboard
Copied
Thanks
Copy link to clipboard
Copied
If this is a federal form remember that whatever you implement must also comply with Section 508 Accessibility Requirements.
Copy link to clipboard
Copied
This is for internal use only. The final scoring is submitted through the Federal Sun system using the totals. I am just trying to make the process easier and (hopefully) eliminate human error with manual calculations.
Copy link to clipboard
Copied
Here's the script that I came up with, but I am not getting any results. I've been combing through the community questions for 3 days now, I just have so many questions. Can I format my "Did Not Occur" answers differently? Could someone help me troubleshoot?
Copy link to clipboard
Copied
Excellent Try!! You're script is close, but needs some fixes in order to operate. For example, variables named "Total" and "n" are declared, but never used. A variable named "nSum" is used, but never declared. And the loop isn't doing anything because the same field is being aquired everytime around the loop. But you've managed to put together a reasonal structure.
Here's an update:
var total = 0, nScore;
for (var i=1; i<=31; i++)
{
nScore = this.getField("Score"+i).value
if (nScore == 3.1)
total += 3;
else if (nScore == 6.1)
total += 6;
else if (nScore == 9.1)
total += 9;
}
event.value = total;
Your first post implies the "3.1", "6.1", and "9.1" are export values from a radio button group. Is this true? if it is, then the the comparison is incorrect. You're not comparing to a number, but to a string. However, it should still work since JavaScript does automatic conversions.
Copy link to clipboard
Copied
Thanks Thom - Since the Select radio button already has score values (for example) 6, 3, 0 - I was trying to make a distinction between a score of 6 when the question's answer was "Did Not Occur." Originally I tried to give it a valuse of 6D, but the letter would not show in the "Score" text box. I did not know if the program would make a distrinction between a "Good" value 6 and a "Did Not Occur" value 6 (the latter is subtracted from the total number of possible points - which impacts the score percent.) So I felt using 6.1 as a distinction would be enough to differenciate, but with rounding would not impact the %.
Thanks for your help Thom, I learned a lot from those articles that many other articles I have read assume a user already knows, such as the meaning of == and &&.
Copy link to clipboard
Copied
Hi Thom - I guess I should have tried the script before replying. I am still not getting a result at all. The box is just blank.
Copy link to clipboard
Copied
Are any errors reported in the console window?
Can you post the form?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That's funny because the form generates a huge list of errors.
First, you copied the code I provided incorrectly.
Second, the "Score" fields are named incosistently. This is the cause of most of the errors. The field names must follow a consistent pattern.
Fix these issue and it will work.
Copy link to clipboard
Copied
Apologies, my misunderstanding. What I meant was that I didn't receive and error message after entering the code. When I ran the debugging script I saw the errors that you must have been referring to. It seems that I had a couple of other fields (not included in the calculation) that had incorrect scripting in them causing the whole form the work incorrectly. With those corrections and your suggestions, my form now appears to be working correctly. Thank you for your help!