2 Replies Latest reply on Aug 21, 2015 1:47 PM by Test Screen Name

    JavaScript Syntax error

    Sean.twyman

      Im gettings a syntax erro and cant figure out why.

      var a = this.getField("P1.B1U"); //checkbox
      var b = this.getField("P1.EBreak1Min");
      var c = this.getField("P1.Break1Min");
      var d = this.getField("P1.Break1OK");
      
      
      if (a.value = "Yes"){ //if checkbox is checked
          if (c.value >= 8 && c.value <= 22){ // then if P1.Break1Min is greater than or equal 8 but less than or eaual to  22
          event.value = (.25);
          d.value = "";
          }
          else if (c.value >= 23 && c.value <= 37){
          event.value = (.50);
          d.value = "";
          }
          else if (c.value >= 38 && c.value <= 52){
          event.value = (.75);
          d.value = "";
          }
          else if (c.value >= 53 && c.value <= 67){
          event.value = (1);
          d.value = "";
          }
      } 
      else if (b.value >= 8 && b.value <= 22){ //P1.B1U not checked and P1.EBreak1Min is greater than or equal 8 but less than or eaual to  22
      event.value = (.25);
      d.value = "";
      }
      else if (b.value >= 23 && b.value <= 37){
      event.value = (.50);
      d.value = "";
      }
      else if (b.value >= 38 && b.value <= 52){
      event.value = (.75);
      d.value = "";
      }
      else if (b.value >= 53 && b.value <= 67){
      event.value = (1);
      d.value = "";
      }
      else{
      event.value = ("0");
      d.value = "Yes";
      }
      
      
      
      
      
      
      
      
      
      
      
      
      
      

       

       

      this is the error I am getting from the java console:

      SyntaxError: syntax error

      12:Field:Calculate

      InvalidSetError: Set not possible, invalid or unknown.

      Field.value:6:Field P1.Break1D:Calculate

        • 1. Re: JavaScript Syntax error
          George_Johnson MVP & Adobe Community Professional

          It's probably due to this line:

           

          1. if (a.value = "Yes"){ //if checkbox is checked 


          Which should be:


          1. if (a.value == "Yes"){ //if checkbox is checked 


          or better yet:


          1. if (a.value === "Yes"){ //if checkbox is checked 



          • 2. Re: JavaScript Syntax error
            Sean.twyman Level 1

            OK i took your suggestions nad used the last option you provided, but now I just get a  generic error....

            "

            SyntaxError: syntax error

            12:Field:Calculate

             

             

            and in another field that the question above references to I have problems with this code at line 5 i believe

             

            var strStart = this.getField("P1.Break1O").value;  //start time
            var strEnd = this.getField("P1.Break1I").value;  //end time
            var a = this.getField("P1.B1U").value//Checkbox
              
            if(var a === "Yes"){ //if checkbox is checked
            event.value = 0; //event value is automatically 0
            }    
            else if(strStart.length && strEnd.length){  
                var timeStart = util.scand("h:MM tt m/d/yy", strStart + " " + util.printd("m/d/yy", new Date()));
                var timeEnd = util.scand("h:MM tt m/d/yy", strEnd + " " + util.printd("m/d/yy", new Date()));
                var diff = timeEnd - timeStart;  
                var oneHour = 60 * 1000;  
                var timeleft = (diff/oneHour);  
            
              if(timeleft > 10){   //checkbox is not checked and timeleft is greater than 10 
              event.value = 10;
                }  
                else  // checkbox not checked and timeleft is less than 10
                event.value = timeleft; 
            }
            else  //strEnd or strStart is empty
            event.value = 0
            
            • 3. Re: JavaScript Syntax error
              Test Screen Name Most Valuable Participant

              You use "var" once to create the variable. You are repeating the "var" incorrectly.