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

Calculation Help - Scoring Sheet

Community Beginner ,
Jul 24, 2023 Jul 24, 2023

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:

Cathy208_0-1690222793252.jpeg

TYIA!

 

 

TOPICS
JavaScript , PDF forms

Views

936

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 ,
Jul 24, 2023 Jul 24, 2023

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 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jul 24, 2023 Jul 24, 2023

Copy link to clipboard

Copied

Thanks

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 ,
Jul 24, 2023 Jul 24, 2023

Copy link to clipboard

Copied

If this is a federal form remember that whatever you implement must also comply with Section 508 Accessibility Requirements. 

 

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 ,
Jul 24, 2023 Jul 24, 2023

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.

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 ,
Jul 25, 2023 Jul 25, 2023

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?

 
var total = 0;
var n = 0;
for (var i=1; i<=31; i++) 
{
if (this.getField("Score"+1).value == 3.1)
{ event.value = 3;}
else if (this.getField("Score"+1).value == 6.1)
{ event.value = 6;}
else if (this.getField("Score"+1).value == 9.1)
{ event.value = 9;}
else 
{ event.value = nSum;}}

 

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 ,
Jul 25, 2023 Jul 25, 2023

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. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jul 26, 2023 Jul 26, 2023

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 &&.

 

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 ,
Jul 26, 2023 Jul 26, 2023

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.

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 ,
Jul 26, 2023 Jul 26, 2023

Copy link to clipboard

Copied

Are any errors reported in the console window?

 

Can you post the form? 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jul 26, 2023 Jul 26, 2023

Copy link to clipboard

Copied

No errors, just nothing showing in the results. Current version attached.

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 ,
Jul 26, 2023 Jul 26, 2023

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. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jul 26, 2023 Jul 26, 2023

Copy link to clipboard

Copied

LATEST

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!

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