7 Replies Latest reply on Dec 11, 2012 12:07 PM by gkaiseril

    keeping a field empty

    James A Hiltz CET Level 1

      the following expression works but if the fields "wd2" and "m2" are accidentally filled in and then deleted the event value displays 0.0

      my goal is simple. if the fields are filled in then deleted the event field should read " ".

       

       

      var m2 = getField("M_2").value; var wd2 = +getField("WD_2").value; if (wd2 === "0.0") { event.value = " "; } else { event.value = (m2 / (wd2 - m2) * 100); } 

        • 1. Re: keeping a field empty
          George_Johnson MVP & Adobe Community Professional

          The following expression should never evaluate to true:

           

          if (wd2 === "0.0")

           

          When this previous line of code is executed:

           

          var wd2 = +getField("WD_2").value;

           

          The value in the variable wd2 is a number, so the strict comparison to the string "0.0" will always be false. I'm not entirely sure how you'd like this to behave, but I think the following should do it"

           

          // Get the field values, as numbers

          var m2 = +getField("M_2").value;

          var wd2 = +getField("WD_2").value;

           

          // If wd2 is blank or zero, set this field to a single space

          if (wd2 === 0) {

              event.value = " ";

          } else {

              //...otherwise, set this field value to the result of the following calculation

              event.value = (m2 / (wd2 - m2) * 100);

          }

           

          I suspect you may want something else. If so, please give more details.

          • 2. Re: keeping a field empty
            James A Hiltz CET Level 1

            Hi George,

             

             

             

            Thank you for the reply.

             

            What you provided me dose work nicely however, I receive the error message “The value does not match the format of the event field” and the event field will not clear if the numbers are removed from wd2 and m2.

             

             

             

            Any suggestions?

             

             

             

             

             

            James A Hiltz CET 

             

            Construction Quality Control, RSO

             

             

             

            Untitled

             

             

             

            [removed personal information]

             

            Proud to be recognized as one of Canada’s top 50 small & Medium Employers.

             

            Message was edited by: sinious

            • 3. Re: keeping a field empty
              George_Johnson MVP & Adobe Community Professional

              Why do you want to set the value of the field to a single space, as opposed to blank?

              • 4. Re: keeping a field empty
                James A Hiltz CET Level 1

                Actually I do want it to be a blank space but it comes up as a single space.

                 

                I guess I am missing a something.

                 

                 

                 

                James A Hiltz CET 

                 

                Construction Quality Control, RSO

                 

                 

                 

                Untitled

                 

                [removed personal information]

                 

                Proud to be recognized as one of Canada’s top 50 small & Medium Employers.

                 

                Message was edited by: sinious

                • 5. Re: keeping a field empty
                  George_Johnson MVP & Adobe Community Professional

                  Because your original code used a single space, that's what I did. If you don;t want that, just remove it in the code so that that one line becomes:

                   

                  event.value = "";  // Blank this field

                   

                  And the error should go away as well.

                   

                   

                  BTW, it seems you're responding by email. When you do that your signature lines are included. They contain some personal info that you might not want displayed in a public forum. I will report this to a moderator so that it will be removed, but you might want to do the same. This issue can be avoided if you reply via the forum instead of email.

                  • 6. Re: keeping a field empty
                    James A Hiltz CET Level 1

                    George,

                     

                     

                     

                    Thank you that fixed my small issue.

                     

                     

                     

                     

                     

                    James A Hiltz CET 

                     

                    Construction Quality Control, RSO

                     

                     

                     

                    Untitled

                     

                     

                     

                    8212 Manning Aveenue

                     

                    Fort McMurray, Alberta

                     

                    T9H 1V9

                     

                    Email: Jim.hiltz@terracon.ca

                     

                    Ph: 780-743-9343

                     

                    Fax: 780-743-2420

                     

                    Proud to be recognized as one of Canada’s top 50 small & Medium Employers.

                    • 7. Re: keeping a field empty
                      gkaiseril MVP & Adobe Community Professional

                      You should only run your script with a non-zero divisor.

                       

                      // Get the field values, as numbers

                      var m2 = +getField("M_2").value;

                      var wd2 = +getField("WD_2").value;

                      event.value = ""; // defalut value

                      // If wd2 is blank or zero set this field to a single space

                      if (wd2 == 0)  {

                          event.value = " ";

                      }

                      // do not calculate if m2 is zero or wd2 - m2 is zero

                      if( ((wd2 - m2) != 0) && (m2 != 0) ) {

                         //...otherwise, set this field value to the result of the following calculation

                          event.value = (m2 / (wd2 - m2) * 100);

                      }