4 Replies Latest reply on Jul 13, 2015 11:12 AM by JohnnyBQue

    Help with radio buttons

    JohnnyBQue Level 1

      I've created a Test with 58 questions....each question has 5 possible answers...I'm using radio buttons to allow the "testee" to choose their answer....There is only one correct answer. I have created the radio button groups call Q1 thru Q58 with the individual choices within the groups call "choicea, choiceb, choicec etc.." what I'm looking for is after all the question have been answered there is a button at the end of the test called "Score Test" when the "Testee" clicks this button first a warning appears if there is a question left unanswered (which they can then go back and choose an answer), second a text box appears showing the score and third I want a text box to appear by each incorrect answer stating "Incorrect; answer is a, b, c, etc..."

      Now I like making these help inquiries a "teachable" moment so if we can do this in sections that would be great...and I understand that I only need the code as if it was for a two question test and I can cut paste the other 56 question if that ends up a cor4rect way of doing the rest of the questions...so I guest the first thing would be ...

       

      A warning that not all the questions have been answered

       

      Next would be to calculate the score and make the text box appear with the score

       

      last would be how to make a text box appear by any incorrect questions AFTER the test has been scored with the statement "Incorrect; answer is a, b, c, etc."

       

      Thanks guys I'll be working on this myself and look forward to you suggestions and techniques....

        • 1. Re: Help with radio buttons
          JohnnyBQue Level 1

          I think for the incorrect answer text boxes I can make one for each question with a Default value representing the correct answer and just toggle the visibility of the text box when ever the question happen to be wrong....

          • 2. Re: Help with radio buttons
            gkaiseril MVP & Adobe Community Professional

            In processing forms with a strict structure a little planning can go a long way in making the programming easier.

             

            I would use hierarchical fields for the answers so the fields for the answers have name like "Q.#" , where "#" is the identifier character for the question. Values of 0 - 58 would allow one to use the for loop or using the "getArray()" method on the top level field to create an array of all the children fields and one can then either use a for loop and using the length of the array of children fields to dynamically set the loop to process the children fields or one could use the for in to process the children fields.

             

            One can test for unanswered radio button field by seeing if the value for the field is "Off" or it is defualtValue of the field.

            • 3. Re: Help with radio buttons
              JohnnyBQue Level 1

              Okay I found this code that was suppose to be for a form with 200 text boxes and checkboxes...I think I can modify it to work for raido buttons.

               

              var emptyFields = [];

              for (var i=0; i<this.numFields; i++) {

                   var f= this.getField(this.getNthFieldName(i));

                   if (f.type!="button" && f.required ) {

                        if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off"))

               

               

              f.strokeColor = color.red;   //Highlights the required fields in red

               

              emptyFields.push(f.name);

                  }

              }

               

              if (emptyFields.length>0) {

                   app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));

              }

              • 4. Re: Help with radio buttons
                JohnnyBQue Level 1

                Okay I got it to works somewhat...by modifying it to whats below...the issue is that all my radial buttons are all being high lighted in RED and the alert window shows all the radio buttons as not being checked even ones that are checked....and as I typed this I noticed that the (f.required) want work because my questions have 5 answers and only 1 is required to be selected so I can't set the default to "as required" fot the code to look for...I do have question as to what to call the radio button the Group scheme like I mentioned earlier is Q1 thru Q52 and the choices with in the group I've named Choicea through Choicee.....now when writing the script how do i identify the single radio button for example (Q1 choicea) what name would I give this radio button?

                 

                 

                var emptyFields = [];

                for (var i=0; i<this.numFields; i++) {

                     var f= this.getField(this.getNthFieldName(i));

                     if (f.type!="button" && f.required ) {

                          if (f.type=="radiobutton" && f.value=="Off")

                 

                f.strokeColor = color.red;   //Highlights the required fields in red

                emptyFields.push(f.name);

                    }

                }

                 

                if (emptyFields.length>0) {

                     app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));

                }