These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Form field validation...

jimratajski
Registered: Apr 26 2006
Posts: 13

I've been struggling with a validation script that I am hoping someone can help me with. I've spent the better part of the day trying variation of snippets I've found online, but nothing seems to work.
 
I have a PDF that contains a quiz. What I am trying to do is to have a text form field either change background color or text color when the proper answer is entered into the field. This will help me to validate correct answers quickly.
 
I'm sure I"m missing something simple, but can't put my finger on it. Any help would be greatly appreciated.
  
Jim

My Product Information:
Acrobat Pro 9.4.3, Macintosh
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You need to clearly define what you are trying to do.

Do you want the validattion as the student completes the question?

By the student after the quiz is complete?

By the instructor after all of the students have completed the test?


George Kaiser

jimratajski
Registered: Apr 26 2006
Posts: 13
This should be validated by the instructor after the students have completed the test. I have already written a script that will email the .fdf file to me for importing into the validation form.

Thanks for your consideration.


Jim
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
The action for a field's "Validation" action is not triggered by an Import FDF action. You will need to write a lengthy script to go through each field and test the value of that field against the correct answer.

You could add a button with JavaSript to perform this task.

// define an array of the field names and correct answers;
var aSolution = new Array(["field1", "a"], ["field2", "true"]);

var nQuestions = aSolution.length; // number of questions;
var nCorrect = 0; // number correct;
var nWrong = 0; // number wrong;
var cTest; // temp variable for student answer

for (i = 0; i < nQuestions; i++) {
cTest = this.getField(aSolution[i][0]).value; // get student answer to question i;
if(cTest.toString() == aSolution[i][1].toString()) {
nCorrect++; // increment correct count
this.getField(aSolution[i][0]).textColor = color.green;
} else {
nWrong++; // increment correct count
this.getField(aSolution[i][0]).textColor = color.red;
} // end test answer;
} // end correct fields
// report results
app.alert("Number correct: " + nCorrect + "\nNumber wrong: " + nWrong, 3, 0);


George Kaiser

jimratajski
Registered: Apr 26 2006
Posts: 13
Thank you for your help George. I'll give this a try.


Jim