Help writing a javascript to only add a positive numbers
If anyone is willing to help I would greatly appreciate it. I have two fields "l1" and "l2" and "l3" that populate with numbers positive or negative. "l4" is supposed to add "l1" + "l2" ONLY if "l2" is positive. If "l2" is negative then this number should not be subtracted from "l1" when these two numbers add together. "l3" will always be a number that is subtracted in this equation. I wrote my script below and it works perfectly when "l2" is positive. When it is negative it subtracts from "l1" which is not what I want. I have looked at this for hours an cannot figure out how to finish this off. Any input would be much appreciated.
var theField = this.getField("l1");
var theValue = theField.value;
var theField2 = this.getField("l2");
var theValue2 = theField2.value;
var theField3 = this.getField("l3");
var theValue3 = theField3.value;
if (((+theValue + +theValue2) - +theValue3) > .001) {
this.getField("l4").value= (((+theValue +
+theValue2) - +theValue3));
}
else {
this.getField("l4").value="";
}
