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

Validating 100% threshold to <99 and >100 between three (3) fields

Contributor ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

Ok, so I've been through the forums and thanks to the SME's have identified a successful method (utilizing a hidden field) to trigger an alert if the total of three (3) fields exceeds 100%.  The discussions on validating below the 100% threshold  have shown why utilizing a calculation script would be, at best, problematic.

With all that being said, I am still attempting to work out validation for <100% threshold by way of validation scripts within the fields: "Percent_01", "Percent_02", "Percent_03".  The "Percent_Total" remains a hidden field for >100% alert and should not factor into the validation scripts, and the "next_field" as a placeholder for whatever the field is to be named.

//Thus far, I am placing the following script in the format tab custom  format script for all "Percent" fields: 

 if (event.value) event.value += "%";

//Percent_01 contains the following validation script:

if (event.value=100) { this.getField("Next_Field").setFocus();
} else {
(event.value <100) (this.getField("Percent_02").setFocus());
}

 

//Percent_02 contains the following validation scrip

var p1 = Number(this.getField("Percent_01").valueAsString);
var p2 = Number(this.getField("Percent_02").valueAsString);
var pt = (p1 + p2);
if (pt =100) { this.getField("Next_Field").setFocus();
else {
pt <100 (this.getField("Percent_03").setFocus());
}

 

//Percent_03 contains the following validation script:

var p1 = Number(this.getField("Percent_01").valueAsString);
var p2 = Number(this.getField("Percent_02").valueAsString);
var p3 = Number(this.getField("Percent_03").valueAsString);
var pt = p1 + p2 + p3
if (pt =100) { this.getField("Next_Field").setFocus(); 
else { 
    pt <100 
    app.alert("Total percentage of benefits to be paid is less than 100%. Your total is : " + event.value + "% Please try again.");
    this.resetForm(["Percent_01""Percent_02""Percent_03"]);
    this.getField("Percent_01").setFocus();
}
 
//Percent_Total contains the following Calculuation script:

event.value = this.getField("Percent_01").value + this.getField("Percent_02").value + this.getField("Percent_03").value;
if (Number(event.value)>100) {
app.alert("Total percentage of benefits to be paid exceeds 100%. Your total is : " + event.value + "% Please try again.");
this.resetForm(["Percent_01", "Percent_02", "Percent_03"]);
this.getField("Percent_01").setFocus();

}

 

Independently, the script for exceeding the maximum value works like a champ.  I have yet to get the below 100% to even work... issues like automatically displaying 100% in the field to not executing to the following field in order.  Any assistance is, as always, much appreciated. 🙂
TOPICS
JavaScript , PDF forms

Views

596

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

correct answers 1 Correct answer

Community Expert , Dec 05, 2022 Dec 05, 2022

FYI:

x= means "x becomes equal to" and x== means "x is equal to", so you must write:

if (event.value==100) {...

with a double-equal sign!

@+

 

Votes

Translate

Translate
Community Expert ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

LATEST

FYI:

x= means "x becomes equal to" and x== means "x is equal to", so you must write:

if (event.value==100) {...

with a double-equal sign!

@+

 

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