4 Replies Latest reply on Jun 23, 2014 6:42 AM by Rhino111

    Custom JavaScript Help

    Rhino111 Level 1

      I have 5 combo boxes with choices of Y, N and NA. When yes is selected the score will equal 3, when no is selected the score will equal 0, when NA is selected the score will show no score. I have a text box that will then show the final score from the 5 combo boxes, out of a possible 15. I have one last text field that will show a pass or fail. A pass would be 15 anything less than a 15 is a fail. I have custom JavaScript stating the following:

       

      var aFields = new Array("6 Combo Box 1", "6 Combo Box 2", "6 Combo Box 3", "6 Combo Box 4", "6 Combo Box 5");

      var aDefault = new Array();

      for (var i = 0; i < aFields.length; i++){

           if (this.getField(aFields[i]).value == this.getField(aFields[i]).defaultValue){  //compares field value to default value which is empty

                aDefault.push(aFields[i]);  //this will create an array of fields not filled in

           }

      }

       

      var v = +this.getField("Model Call Score").value;

      if (v>14) event.value = "Pass";

      else event.value = "Fail";

       

       

      //verify if aDefault contains at least one field

      if (aDefault.length >0){

           event.target.display = display.hidden; 

      //hide my value if a field is still empty

       

      }

      else{

           event.target.display = display.visible;

      }

       

      I understand that the last part of the code said to make the value hidden. I want a pass or a fail to show up only when all combo boxes are selected. I do not have knowledge of JavaScript. Could someone please help me correct my current code or come up with another suggestion. Attached is a link to my form. My above question is referring to the bottom section.

        • 1. Re: Custom JavaScript Help
          try67 MVP & Adobe Community Professional

          Change this line:

          if (this.getField(aFields[i]).value == this.getField(aFields[i]).defaultValue){  //compares field value to default value which is empty

          To this:

          if (this.getField(aFields[i]).value === this.getField(aFields[i]).defaultValue){  //compares field value to default value which is empty

          • 2. Re: Custom JavaScript Help
            Rhino111 Level 1

            Wicked! Thanks so much! I have one last question regarding this form. Earlier in my form I have 5 sections of combo boxes. Each section contains 4 choices. They then populate a score then an average score then a final average score. The issue I'm having is if the user selects NA it no longer counts in the score, the score would now be based out of 3 and not 4. If they select NA twice the score would be based out of 2 and not 4. How can I write a custom JavaScript that lets me say what the score will be based on if the user selects NA.

            • 3. Re: Custom JavaScript Help
              try67 MVP & Adobe Community Professional

              You need to write a script that goes over the fields, checking if their value is "NA" (or blank), and if not it adds their value to a "total" variable and increments a "counter" variable. At the end it divides the total value by the counter (if it's not 0, of course).

              • 4. Re: Custom JavaScript Help
                Rhino111 Level 1

                Yes, that makes sense, are you able to help me write that code?