• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Can I get some help with validation script?

Explorer ,
Apr 06, 2021 Apr 06, 2021

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.

TOPICS
How to , JavaScript , PDF forms

Views

676

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2021 Apr 06, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 06, 2021 Apr 06, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2021 Apr 06, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 06, 2021 Apr 06, 2021

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2021 Apr 07, 2021

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 = "";
		}
	}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

LATEST

Great. Thanks for your help. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines