Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Need to blank calculated field depending in calculation

Avatar

Not applicable
I am having a simple form derived from the examples, which shows numSum = numQty*numCost.

This works fine and numSum is blank until both operands are entered.

But if add other fields for numDiscount and finalSum with the caluculation



finalSum = numQty*numCost - (numQty*numCost /100 * numDiscount)



then finalSum always displays 0.00 regardless whether the previous fields have been filled or not.



How can this be avoided?



regards, Dieter
1 Reply

Avatar

Level 1

//------------------------------------------------------------------------------------

// 1st parameter array with names of fields for check

// 2nd parameter is string "All" or "One" ...determine all or one must be not null ...

//------------------------------------------------------------------------------------

function MyCheckValueToNull(aFieldsNames,OneOrAll)

{

   var All_IsNotNull = 1;

   var One_IsNotNull = 0;

   for (i = 0; i < aFieldsNames.length; i++) {

       if(getField(aFieldsNames[i]).value === ""){

          All_IsNotNull = 0;

       }else{

          One_IsNotNull = 1;

       }

   }

   if(OneOrAll == "One"){

      return One_IsNotNull;

   }else if(OneOrAll == "All"){

      return All_IsNotNull;

   }else{

      return null;

   }

}

//----------------------------

//--- sample how to use ------

      var aFieldsNames = [

          "numQty",

          "numCost",

          "numDiscount"

      ];

      var lCheck = MyCheckValueToNull(aFieldsNames,"All");

      if(lCheck == 1){

         event.value = getField(aFieldsNames[0]).value*getField(aFieldsNames[1]).value - (getField(aFieldsNames[0]).value*getField(aFieldsNames[1]).value /100 * getField(aFieldsNames[2]).value);

      }else{

         event.value = "";

      }