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

Adobe Form - Script Help! - Automatic Comparison of fields, based on the value of another.

Community Beginner ,
Jan 20, 2024 Jan 20, 2024

Hello, Looking for a bit of assistance and guidance with the below, I am normally quite good at bumbling along problem solving basic Javas as I go, but I want to actually learn on this one rather than bumble through it. 

 

I have a table (below) which will summary the answers from a multi choice exam paper, there are 3 elements I want to automate within the form.

 

The first is the one I have least chance of solving on my own, I want to create a script that will display the correct answer in the 'Correct Answer" Column depending on the entry into the Question Number column fields (i.e. if Question Number field is "3" this will equal "A" in the corrosponding Correct Answer field or "5" will equal "C" etc. 

Conor24942946jf1i_0-1705760962871.png

There are 14 questions and the candidates are to choose any 10. so the script will need to be flexible to allow for any number in the column1 fields to result in a different answer in the 'Correct Answer' column. I have the Question Number fields to number only. The correct answers for the questions are below. 

Conor24942946jf1i_1-1705761300065.png

 

Second part is I want to script is a comparison between the script filled field above (correct answer) and the corrosponding manually entered Skilled Person Answer (column 2) if these are the same I want the Y/N check box to be triggered if these values match. 

 

Third and final stage is for the Y/N Total Correct Field to be essentially a count of the fields above it, if there are 8 check boxes activated, then I want this field to be 8. 

 

Any gudiance would be apprecaited. 

 

TOPICS
JavaScript , PDF forms
1.5K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jan 21, 2024 Jan 21, 2024

Use this:

var cList = [
{Q:1,A:"A"},
{Q:2,A:"A"},
{Q:3,A:"B"},
{Q:4,A:"A"},
{Q:5,A:"A"},
{Q:6,A:"C"},
{Q:7,A:"C"},
{Q:8,A:"C"},
{Q:9,A:"A"},
{Q:10,A:"D"},
{Q:11,A:"C"},
{Q:12,A:"C"},
{Q:13,A:"B"},
{Q:14,A:"B"}];

for(var j=1; j<=10; j++) {
var q = Number(this.getField("Question NumberRow" +j).valueAsString);
var a = this.getField("Correct AnswerRow" +j);
var matchFound = false;

for(var i=0; i<cList.length; i++) {
if (q == cList[i].Q) {
a.value = cList[i].A;
matchFound = true;
break;}}

if (!matchFound)
a.value = "";}

View solution in original post

Translate
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 ,
Jan 20, 2024 Jan 20, 2024

I'm not sure if I understood how you wish the first part to work, if the user enters anything in 'question' field you want to show the correct answer in 'Answer' field?

Try this and see if that is what you look for (put it in one of the fields as custom calculation script):

var cList = ["A","A","B","A","A","C","C","C","A","D","C","C","B","B"];
for(var i=1; i<=14; i++){
var Q = this.getField("Question NumberRow"+i).valueAsString;
var A = this.getField("Correct AnswerRow"+i);
if(Q !== "")
A.value = cList[i-1];
else
A.value = "";}

 

Translate
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 ,
Jan 20, 2024 Jan 20, 2024

Hi Nesa, That certainly seems to function exactly as I had hoped., Thank you. 

 

Works perfectly for the first 10, Only issue I have now is it is getting the answers wrong for 11, 12, 13 and 14. It isn't picking the corrosponding CList digits.

Translate
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 ,
Jan 20, 2024 Jan 20, 2024

That's because I thought you have 14 fields, but I just saw there are only 10 fields and 14 questions.

What exactly does user input into question fields?

Do they input numbers from 1-14, and you want to show correct answer for that number?

Translate
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 ,
Jan 20, 2024 Jan 20, 2024

Yes the user will input numbers from 1 - 14 and I want the form to show the correct answer for that number. 

The candidate has 14 questions and they get to pick any 10 to do so any number can theoretically be skipped. 


Translate
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 ,
Jan 21, 2024 Jan 21, 2024

Use this:

var cList = [
{Q:1,A:"A"},
{Q:2,A:"A"},
{Q:3,A:"B"},
{Q:4,A:"A"},
{Q:5,A:"A"},
{Q:6,A:"C"},
{Q:7,A:"C"},
{Q:8,A:"C"},
{Q:9,A:"A"},
{Q:10,A:"D"},
{Q:11,A:"C"},
{Q:12,A:"C"},
{Q:13,A:"B"},
{Q:14,A:"B"}];

for(var j=1; j<=10; j++) {
var q = Number(this.getField("Question NumberRow" +j).valueAsString);
var a = this.getField("Correct AnswerRow" +j);
var matchFound = false;

for(var i=0; i<cList.length; i++) {
if (q == cList[i].Q) {
a.value = cList[i].A;
matchFound = true;
break;}}

if (!matchFound)
a.value = "";}
Translate
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 ,
Jan 21, 2024 Jan 21, 2024
LATEST

Wonderful Nesa, Thank you very much. 

Managed to sortthe other two bits easily. Thanks again. 

Translate
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