1 Reply Latest reply on Feb 16, 2010 6:30 AM by pguerett

    Trying to divide two numeric fields and have answer in third num field

    ndjustin20 Level 1

      Ok I am doing something wrong and can't figure it out.  I am using the below code inside the psf field of my form to divide two different numeric fields and for the life of me I can't figure out why it isn't working.  I'm assuming it is something simple.  I have uploaded the form.  Please take a look at the form and le me know where I am off.  It almost has to be something simple and something I'm just not seeing

       

      <event activity="click" name="event__click">

      <script contentType="application/x-javascript">

       

      if (NumericField13.isNull || NumericField13.rawValue == 0)

      {

      NumericField28.rawValue = "0";

      }elseif(NumericField27.isNull || NumericField27.rawValue == 0){

      NumericField28.rawValue = "0";

      }else{

      NumericField28.rawValue = NumericField13.rawValue / NumericField27.rawValue;

       

      }

      </script>

      </event>

       

      I think it has something to do with how the division is being done.  I'm thinking that it is trying to divide by zero though at this point I have tried several differnt if/then statements and can't see where I am off in the equation so I tried the above as a click even and couldn't get that to work either.

       

      Thank you in advance for your assistance.

       

       

      Justin

        • 1. Re: Trying to divide two numeric fields and have answer in third num field
          pguerett Level 6

          First thing is that you have that script executing on the click event....so your code will not execute until a user clicks on the field. I suggest you put it

          on the calculate event. That way whenever one of the other values named in the formula changes t

          hen it will recalc this field.

           

          Second there was a script error in your formula....I modified it to look like this (it just seems more logical this way to me)

           

          if (NumericField13.isNull || NumericField13.rawValue == 0){
          NumericField28.rawValue = "0";
          }else {
          if(NumericField27.isNull || NumericField27.rawValue == 0){
            NumericField28.rawValue = "0";
          }else{
            NumericField28.rawValue = NumericField13.rawValue / NumericField27.rawValue;
          }
          }

           

          Third your NumericField27 shodul have a default value of 1 or you should do acheck of its value so that it does not have a possibility of getting a 0 or your division will fail.

           

          Lastly, you shodul rename your fields to have more descriptive names insstead of generic names like numericField XX. Many people liek to know the type of field by the name so instead of NumericField27 how about SQFT_NumFld? With this technique I can tell immeadiately which field you are referring to (Square Footage) as well as its type (Numeric Field). Just my 2 cents worth!

           

          Paul