6 Replies Latest reply on Mar 17, 2008 9:24 AM by (Meabh)

    problem with script

    Level 1
      Heres the form:

      (Field name = calc)
      10.1 = 9.1 x 6.1
      12.1 = 8.1 - 11.1
      13.1 = lesser of 10.1 or 12.1. If 12.1 is less than $50.00, then $50.00

      10.1 and 12.1 are working just fine but 13.1 eludes me. The script runs in debugger but I can't get a value in the actual field.

      var f = this.getField("10.1").value;
      var g = this.getField("12.1").value;
      var k = this.getField("13.1").value;
      {
      if (f < g){
      k = f;
      }else
      if (g < "50.00"){
      k = "50.00";
      }else
      k = g;
      }

      Any ideas what I'm missing?
      Thanks
      Meabh
        • 1. Re: problem with script
          Bernd Alheit Adobe Community Professional & MVP
          > The script runs in debugger but I can't get a value in the actual field.

          Where did you set the value of the actual field?
          • 2. Re: problem with script
            Level 1
            nada, zip, zilch, just a blank field
            • 3. Re: problem with script
              gkaiseril MVP & Adobe Community Professional
              You need to access the value of field's "13.1" object not just the value of the field placed in a variable. Also do not put numbers in quotes because you will be comparing a number to a character string and they are never equal beccause they are different types.

              // original code with some debugging information
              var f = this.getField("10.1").value; // variable f is the value of the field but it is not the field's value property
              var g = this.getField("12.1").value; // variable g is the value of the field but it is not the field's value property
              var k = this.getField("13.1").value; // variable k is the value of the field but it is not the field's value property
              // some debugging information
              console.show();
              console.println("Before if:");
              console.println("this.getField(\"10.1\").value: " + this.getField("10.1").value);
              console.println("f= " + f + " typeof: " + (typeof f) );
              console.println("this.getField(\"12.1\").value: " + this.getField("12.1").value);
              console.println("g= " + g + " typeof: " + (typeof g) );
              console.println("this.getField(\"13.1\").value: " + this.getField("13.1").value);
              console.println("k= " + k + " typeof: " + (typeof k) );
              console.println("(g < \"50.00\"): " + (g < "50.00") );
              // end debugging
              {
              if (f < g){
              k = f; // set the variable k to the value of variable f
              }else
              if (g < "50.00"){ // is the number 50 less than the string "50.00"?
              k = "50.00"; // set the variable k to the string "50.00"
              }else
              k = g; // set the variable k to the value of variable g
              }
              // some debugging information
              console.println("After if:");
              console.println("this.getField(\"10.1\").value: " + this.getField("10.1").value);
              console.println("f= " + f + " typeof: " + (typeof f) );
              console.println("this.getField(\"12.1\").value: " + this.getField("12.1").value);
              console.println("g= " + g + " typeof: " + (typeof g) );
              console.println("this.getField(\"13.1\").value: " + this.getField("13.1").value);
              console.println("k= " + k + " typeof: " + (typeof k) );
              // end debugging

              // modified code with the same debugging information
              var f = this.getField("10.1").value; // variable f holds the value of the field but it is not the field's value property
              var g = this.getField("12.1").value; // variable g holds the value of the field but it is not the field's value property
              var k = this.getField("13.1"); // variable k is the object for field "13.1" and each property to be accessed or method to be used can be added as required.
              // some debugging information
              console.show();
              console.println("Before if:");
              console.println("this.getField(\"10.1\").value: " + this.getField("10.1").value);
              console.println("f= " + f + " typeof: " + (typeof f));
              console.println("this.getField(\"12.1\").value: " + this.getField("12.1").value);
              console.println("g= " + g + " typeof: " + (typeof g));
              console.println("this.getField(\"13.1\").value: " + this.getField("13.1").value);
              console.println("k= " + k + " typeof: " + (typeof k));
              console.println("(g < 50.00): " + (g < 50.00) );
              // end debugging
              {
              if (f < g){
              k.value = f; // set the value property of object k to the value of variable f
              }else
              if (g < 50.00){ // compaere as a number
              k.value = 50.00; // set the value property of ogject k to the number 50
              }else
              k.value = g; // set the value property of object k to the value of variable g
              }
              // some debugging information
              console.show();
              console.println("Afer if:");
              console.println("this.getField(\"10.1\").value: " + this.getField("10.1").value);
              console.println("f= " + f + " typeof: " + (typeof f));
              console.println("this.getField(\"12.1\").value: " + this.getField("12.1").value);
              console.println("g= " + g + " typeof: " + (typeof g));
              console.println("this.getField(\"13.1\").value: " + this.getField("13.1").value);
              console.println("k= " + k + " typeof: " + (typeof k));
              // end debugging
              • 4. Re: problem with script
                Level 1
                Thank you Geo, I finally figured out the .value bit and its doing what I want it to do.

                However I have a new problem with another script.
                14.2 - 3 check boxs same field name diff export values

                var e = this.getField("13.1").value;
                var f = this.getField("14.2").value;
                var g = this.getField("14.1");
                var h = 4.33;
                var i = 2.17;

                if(f == "weekly"){
                g.value = e*h
                }
                if(f == "bi-weekly"){
                g.value = e*i
                }
                else if(f == "monthly"){
                g.value = e
                }

                Its in the MouseUp and OnBlur event of the check boxes. Nothing happens but when I run it in Debugger, I get a result WHICH THEN POPULATES 14.1.

                Which foot am I stepping on?
                Thanks
                Meabh
                • 5. Re: problem with script
                  gkaiseril MVP & Adobe Community Professional
                  Add some "console.println()" and see what is being done. You could also simplify you script by replacing the export value of the check boxes from the spelled out period to the value for the computation. You also do not take into account the situation when no check box is selected. You only need to put the script in the mouseup action.

                  var e = this.getField("13.1").value;
                  var f = this.getField("14.2").value;
                  var g = this.getField("14.1");

                  console.println("13.1 = " + e);
                  console.println("14.1 = " + g);
                  console.println("14.2 = " + f);

                  if(f == "Off"){
                  g.value = "";
                  } else {
                  g.value = e * f;
                  }
                  • 6. Re: problem with script
                    Level 1
                    Much head banging later but its finally working. Had to place the final script in the text field not the check boxes.

                    Thanks for all your help,
                    Meabh