Skip to main content
January 16, 2020
Question

How to code the check the value of 2 form fields that must total a specifc number or more

  • January 16, 2020
  • 1 reply
  • 812 views

I have a form here that i'm 98% complete but I just can't figure out one slight detail.

I'm trying to calculate the total of 2 fields to display in a read only field. That part i got worked out half way. It only works to add, if a value that is lesser than the previously entered value, the one field does not redo the math. it simply leaves the original value and stops working. Here is what i need to do.

Form field names:

PWR GVWR
TRL GVWR (this field has to have a value of 10,001 or more, if it does not, must show a flag to the user, that is must be greater than 10,000)

TOTAL GVWR TEXT (Just displays but doesn't print the words TOTAL GVWR. Simple and no need for help on this)

TOTAL GVWR (must have a value of 26001 or more when PWR GVWR and TRL GVWR values are entered. If the total of both do not =26001 or more, then flag the user. this i know how to set the value range which is easy.)

 

I need PWR GVWR + TRL GVWR to add and display those 2 added values into TOTAL GVWR text box. That value needs to be checked to see if it is greater than 26,000. If it is not, it needs throw up a flag to the user and state, that the TOTAL GVWR must be 26,001 or greater. The TRL GVWR field has to have a value of 10,001 or more. If it's not, it throws up a flag to the user to state, the TOTAL GVWR must be greater than 10,000.

 

What i'm having an issue with is 2 sided. First, when i enter 1000 into PWR GVWR and say 29000 into the TRL GVWR the total is added together and displayed in the TOTAL GVWR field. This only works one way. If i reduce the value in the TRL GVWR field, to 27000, the TOTAL GVWR field still shows 30000 and does not do the addition of the 2 fields again. It simply keeps the first entered information in there and stops. Same thing happens if i do the changing in the PWR GVWR field. Does the math once as addition, then stops and if a value is changed it doesn't change the TOTAL GVWR field to display the correct value.

 

Any idea's on how i can get this code to work right?

Here is my code as it sits in each field.

PWR GVWR: Calculate tab, custom script selected.
Code:

var totVal = this.getField("PWR GVWR").value + this.getField("TRL GVWR").value;

if(totVal <26001){
this.getField("Print Button").readonly = true;
}
else
{
this.getField("Print Button").readonly = false;
}

 

TRL GVWR properties: Validate tab, Value is in range from 10001 to 0. Calculate tab:

Code:
var totVal = this.getField("PWR GVWR").value + this.getField("TRL GVWR").value;

if(totVal <26001){
this.getField("Print Button").readonly = true;
}
else
{
this.getField("Print Button").readonly = false;
}

 

TOAL GVWR field properties: Validate tab, value is in range 26001 to 0. Calculate tab, value is the sum+ of the following fields: PWR GVWR, TRL GVWR.

 

In other words what i need this form to do properly is check the math both ways in the PWR GVWR and the TRL GVWR fields to make sure they have a total value of 26,001 or more but the TRL GVWR has to have a value of 10,001 or more no matter what. It does the addition once, then stops. I need it to check the values of both fields no matter what is entered so it can be verified that they both total 26,001 or more. Here are a couple of number examples i use

 

1000 + 25000 = 26000 (flags an error to the user)

1100 + 25000 = 26100 (no flags continue one with your work)

24000 + 10000 = 34000 (flags the error to the user, the TRL GVWR must have a value of 10001 or more. Even though the TOTAL GVWR is greater than 26001, the TRL GVWR field is less than the allowed limit.)

 

 

 

 

This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
January 16, 2020

Check the field calculation order.

January 16, 2020

I"m not sure what you mean by that. If i change the order i which i select the form fields to calculate it automatically puts them in it's own order by alphabet.

Bernd Alheit
Community Expert
Community Expert
January 16, 2020

Under Prepare Form look at "More" on the right side.