Hello to all!
Trying to get my if/else statement to work but its not working :/. I need a second opinion and how I can make it work. This code will be going in the Total Price column (where it says $0.00). Thank you in advance!
Here is what I am trying to accomplish:
var v1 = this.getField("txtDoughUnit1").value;
var total = v1 * 14;
if(150 > total) event.value = total;
else if((total >= 150 ) && (total < 300)) event.value = total * 0.40;
else if(300 >= total) event.value = total * 0.50;
else event.value = 0;
What is not working in your script?
Check your comparison operator for the units below 150.
Adding comments to your code can make your code easier for others to read and help you at a later date when you need to update the code.
I would use the "switch" statement.
// units for computing discount
var nTotal = this.getField("txtDoughUnit1").value * 14;
// select when statement is true
case (nTotal >= 300) :
// total greater than 300
event.value = nTotal * 0.50;
break; // end greater than 300
case (nTotal >= 150 ) :
// total greater than or equal to 150 and less than 300
event.value = nTotal * 0.40;
break; // end greater than or equal to 150, greater than 300 all ready done
// all other values
event.value = 0;
} // end of switch decision
Thanks! I was able to take your code and tweak it and I have it working now. Your help is much appreciated! I have never used the Switch statement before. Learn something new every day!