Copy link to clipboard
Copied
I'm working on a form and I have to make a validation script and I have no idea what I should do. I'm not versed in javascript and am struggling. Can use some help.
"MAX" is my maximum value
"POINTS" is a value that will be subtracted from MAX
"CURRENT" is the value derived from "MAX" minus "POINTS"
"ADJUST" is another value I want to use to validate the "CURRENT" value.
I want the "CURRENT" field to be validated so that it never goes higher than "MAX" minus "ADJUST".
I hope that all makes sense.
Copy link to clipboard
Copied
Is CURRENT automatically calculated, then, or a user-input value?
If the former, what should happen if it is higher than MAX minus ADJUST?
Copy link to clipboard
Copied
CURRENT is a calculated field based on user input and it can be higher than MAX - ADJUST. In that case, I want it to show the negative value. Or better yet, is there a way for it to show some sort of warning or message indicating it's negative and not allowed? If not then it's ok if it just shows the negative value. My main concern is making sure the CURRENT will never go over MAX-ADJUST.
Thank you for your interest in helping.
Copy link to clipboard
Copied
I don't understand what you mean by "a calculated field based on user input". Which user input? Based on what fields?
Copy link to clipboard
Copied
The CURRENT field value is calculated from user input from several dozen other fields that can have a positive or negative value. The sum of those other fields is subtracted from the MAX field to give me the value in the CURRENT field. So that the CURRENT field can go up or down according to the value of those fields that are calculated for it. My goal is to restrict the CURRENT field to never go over the value of MAX minus the ADJUST field.
Copy link to clipboard
Copied
Try this:
if (event.value) {
if (event.value<0) {
app.alert("You may not enter a negative value.");
event.value = "";
} else {
var max = Number(this.getField("MAX").valueAsString);
var adjust = Number(this.getField("ADJUST").valueAsString);
if (event.value>(max-adjust)) {
app.alert("You may not enter a value that's higher than MAX-ADJUST.");
event.value = "";
}
}
}
Copy link to clipboard
Copied
Great. Thanks for your help.