1 Reply Latest reply on Jul 29, 2011 4:54 PM by George_Johnson

    creating a score in a text field based on the selection in the list box

    Curry Monsta

      I am attempting to use the forms design in pdf for educational purposes.


      I have layed out my form with a set of questions with each question having a listbox with possible answers that you can select from with a hidden text field next to the list box.


      the intention is that the hidden text field will either hold the value 1 if the answer selected from the list box is correct or 0 if it is incorrect.


      At the end I also have another text field which will return the overall score.


      I am sure too most of you this will sound incredibly easy tosort out but I have no experience of javascript and I am sure that is whats needed to do this form the litlte bit of digigng and explring I have done.


      Please help !

        • 1. Re: creating a score in a text field based on the selection in the list box
          George_Johnson MVP & Adobe Community Professional

          You may not need to use the hidden text fields and instead set up the final score field with a custom calculation script that checks each of the list boxes to see if a correct answer is given. If you set the export value of each correct answer for each list box to 1 (or "correct", or something else as long as they are all the same), and the export value of the incorrect answer to something else (choose unique values for each item in a particular list box), the script could get the value of each list box, see if it's equal to 1 (or whatever you've chosen to indicate a correct answer), and increment a counter. Then set the calculated value of the field to the sum. Here's some code that demonstrates the idea:


          // Custom Calculate script for text field
          (function () {
              // Declare variables, initialize counter
              var i, v, sum = 0;
              // Loop through the list boxes and keep track of correct answers
              for (i = 1; i < 11; i++) {
                  // Get the list box value
                  v = getField("List" + i).value;
                  // Increment the counter if correct
                  if (v == 1) sum += 1;
              // Set this field value to the number of correct answers
              event.value = sum;


          This code assumes 10 list boxes named "List1", "List2", ..."List10", so you have to alter to suit your setup.