9 Replies Latest reply on May 26, 2013 10:58 AM by AffordableParalegal

    Error in Javascript

    AffordableParalegal Level 1

      Capture 12.PNGCode that is causing problem is in first field of the form below TOTAL, called "TSM"

       

      This is the error:  Syntax error: missing ) before condition 9 at line 8

      This is a link to a usable form (I think)  https://workspaces.acrobat.com/?d=eHgoPUbA1ZDY0TyH3CcHRQ

       

       

      This is the code

       

      var c = this.getField("TM")                                         //Gets total mileage from field "TM"

      var d = this.getField("StandardCost")                        //Gets dollar amount from "StandardCost"

      var e = this.getField("Cb")                                         //Gets value of Checkbox

       

      if ((event.e.value = No)||(event.d.value!=0)){            //If the Checkbox is not checked and there the fee is greater than zero; Mileage X cost = "TSM"

      event.value =c.value * d.value;

      }

          else if{

            ((event.e.value = No)||(event.d.value=0)){           // if the fee is zero and Checkbox is not checked there is no value

                  event.value = "";

          else if{

      (event.e.value = Yes) {                                              //If the checkbox is checked the TSM field is not visible.

                  TSM.hidden = true;

      }

        • 1. Re: Error in Javascript
          gkaiseril MVP & Adobe Community Professional

          If "Yes" and "No" are string values they should be in quotes.

           

          "true" and "false" are logical system variable so they are not quoted.

           

          Unchekced check boxes and radio buttons in Acrobat forms have a value of "Off".

          • 2. Re: Error in Javascript
            try67 MVP & Adobe Community Professional

            In addition to George's comments: To compare two values you must use the comparison operator ("=="), not the assignment operator ("=").

             

            Also, there's no such object as "event.e" and you're missing a closing parenthesis (as the error message suggests).

            1 person found this helpful
            • 3. Re: Error in Javascript
              AffordableParalegal Level 1

              I agree as to the "event.e" - that was an experiment and although no errors are generated because of it, it is not correct syntax.

              As to other remarks, not so sure. 

              The misuse of brackets was the problem.

              This code generates no error

               

              var c = this.getField("TM")

              var d = this.getField("StandardCost")

              var e = this.getField("Cb")

               

               

              if ((e.value = "yes")||(d.value!=0)){       

              event.value = (c.value * d.value);         

              }                                                    // needed this bracket

                        else if

                          ((e.value = "yes")||(d.value=0))

                          {      

                                event.value = "";

              }

                        else if                                      

              (e.value = "no") {        

                                            TSM.hidden = true

              }

              • 4. Re: Error in Javascript
                Test Screen Name Most Valuable Participant

                ((e.value = "yes")||(d.value=0)


                This is VERY wrong as noted in reply#2. It is not a syntax error, it just doesn't do what you want.

                • 5. Re: Error in Javascript
                  try67 MVP & Adobe Community Professional

                  As to other remarks, not so sure.

                  Well, you should heed the advice given to you... Until you fix all of the issues mentioned above, your code is not going to work correctly.

                  • 6. Re: Error in Javascript
                    AffordableParalegal Level 1

                    agree; I am past the syntax error and now working on problems.

                    • 7. Re: Error in Javascript
                      AffordableParalegal Level 1

                      Made changes as follows but still not getting form fields to be not visible. Does display.hidden apply only to text fields and not number fields?

                      Getting ahead of myself a bit but the next problem I need to work on is to add condition for when mileage calculation is changed to automatically change price. I am wondering if this is a condition better made on a document level instead of object level?

                       

                      var c = this.getField("TM")

                      var d = this.getField("StandardCost")

                      var e = this.getField("Cb")

                       

                       

                      if ((e.value = "Yes")&&(d.value!=0)){       

                      event.value = c.value * d.value;         

                      }

                                else if

                                  ((e.value = "Yes")&&(d.value=0))

                                  {      

                                        event.value = "";

                      }

                                else if                                      

                      (e.value != "Yes") {        

                                                    getField("TSM").display = display.hidden

                                                    getField("FC").display = display.hidden

                                                    getField("SC").display = display.hidden

                                                    getField("M1").display = display.hidden

                                                    getField("M2").display = display.hidden

                      }else{

                                                    getField("TSM").display = display.visible

                                                    getField("FC").display = display.visible

                                                    getField("SC").display = display.visible

                                                    getField("M1").display = display.visible

                                                    getField("M2").display = display.visible

                                                    }

                      • 8. Re: Error in Javascript
                        try67 MVP & Adobe Community Professional

                        You did not fix the use of the assignment operator in your if-statements, which was pointed out twice.

                         

                        And the display property applies to all fields.

                        • 9. Re: Error in Javascript
                          AffordableParalegal Level 1

                          if you mean logical operators, I changed them and the code works fine. Thanks.