Math.max(a, b) returns the greater value of the two. Math.min(a, b) returns the smaller value of the two. (actually, you can pass more than two arguments, and it will return the greatest or smallest of them all). For your example, may I assume that the searched result is filled into field "TOTALDrinkingWaterCommitment". In this case, I would do the following var daSum = a.value*1 + b.value*1 + c.value*1 + d.value*1 ; event.value = Math.min(561073, Math.max(1090, daSum)) ; And that should do it (and I did count the parentheses…). Note the multiplication by 1 for the four summands. This forces the values to be numbers, so that they are actually added. Otherwise, as soon as one field is empty, the value would be the empty string, and instead of adding up, the numbers would be concatenated. …welcome to the great world of JavaScript…
... View more