Skip to main content
Participant
January 18, 2024
Question

Calculated values not calculating correctly all every time

  • January 18, 2024
  • 1 reply
  • 627 views

If written the following script and I've found that it's working some of the time but not all of the time. For example when I have the size as 1/6 and the cost anywhere from 275-396 the value should be 7.00 but it puts it as 5.00. When I type 397 it changes to 7.00. I can't determine why it's not calculating correctly every time. 

 

var size=(this.getField("KegSize").value);
var cost=Number(this.getField("KegCost").value);
var ABV=Number(this.getField("ABV").value);
if (size="1/6")var product1=Number(cost/640);
if (size="1/4")var product2=Number(cost/992);
if (size="1/2")var product3=Number(cost/1984);
if ((ABV>1)&&(product1>.2))event.value="7.00"; else if ((ABV>1)&&(product1<.2))event.value="5.00"; else if (ABV<1) event.value="";
if ((ABV>1)&&(product2>.2))event.value="7.00"; else if ((ABV>1)&&(product2<.2))event.value="5.00"; else if (ABV<1) event.value="";
if ((ABV>1)&&(product3>.2))event.value="7.00"; else if ((ABV>1)&&(product3<.2))event.value="5.00"; else if (ABV<1) event.value="";//

 

 

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
January 18, 2024

For comparisons use ==, not =.

For example:

if (size=="1/6")

Participant
January 18, 2024

Thank you. I changed that and it still isn't calculating correctly. It's so random how some numbers give the correct values and others don't. If it was totally broken that would be one thing but it switches back and forth between 5 and 7 - just not always correctly.

try67
Community Expert
Community Expert
January 18, 2024

Check the fields calculation order. If it still doesn't work, please share the actual file with us.