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

How to limit the figure?

New Here ,
Jul 22, 2018 Jul 22, 2018

Copy link to clipboard

Copied

Initial:

When I input 60 in Field A and 80 in field B. Nothing is appeared when the total amount is smaller than 100

When I input 60 in Field A and 80 in field B. Alert is appeared when the total amount is greater than 100.

Alert is appeared when the total amount is greater than 100. The Alert message is "the total amount cannot be exceed 100"

How to make relevant javascript code for this activity?? Thank you.

TOPICS
Acrobat SDK and JavaScript

Views

136

Likes

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 ,
Jul 22, 2018 Jul 22, 2018

Copy link to clipboard

Copied

Create a total field that has a calculated value which is the sum of fields A and B. It can be hidden.

Then add the following as its custom Validation script:

if (event.value>100) app.alert("The total amount cannot be exceed 100.");

Likes

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
New Here ,
Jul 22, 2018 Jul 22, 2018

Copy link to clipboard

Copied

Thank you for your reply.

However, there is no space for me to create a total field in the PDF. I want to insert relevant code in Field B instead of new total field.

Meanwhile, I want to add a necessary function below.

"After the alert message is closed. The data in Field B (means 80) is deleted automatically for re-inputted."

Do you have any alternative code? Thank you very much.

.

Likes

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 ,
Jul 22, 2018 Jul 22, 2018

Copy link to clipboard

Copied

The Total field can be 1x1 pixels... But if you want to reject the value then you must apply a validation script to field B.

However, think about this scenario:

They enter 80 in field B (which is accepted), then they go back to field A and enter 40. The value is also accepted because the value of B didn't change, so the validation script didn't execute.

In short, you would need to apply a script for both fields, to make sure it works correctly.

Likes

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
New Here ,
Jul 22, 2018 Jul 22, 2018

Copy link to clipboard

Copied

Thank you for your reply again. I will create 1x1 pixels of total field.

Meanwhile, what is the relevant code for the subsequent activity below ?

"The data in Field B (means 80) is deleted automatically for re-inputted after the alert message is closed."

Likes

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 ,
Jul 22, 2018 Jul 22, 2018

Copy link to clipboard

Copied

You don't need a Total field if you use this approach.

Anyway, apply this code as the custom validation script of field A:

if ((Number(event.value) + Number(this.getField("B").valueAsString))>100) {

    app.alert("The sum of the two fields can not exceed 100.");

    event.rc = false;

}

And this as the custom validation script of field B:

if ((Number(event.value) + Number(this.getField("A").valueAsString))>100) {

    app.alert("The sum of the two fields can not exceed 100.");

    event.rc = false;

}

Likes

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
New Here ,
Jul 22, 2018 Jul 22, 2018

Copy link to clipboard

Copied

LATEST

Thank you Thank you.

You help me solve the great problem and save me huge time.

Likes

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