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

How restrict a field by Min-Max value

Explorer ,
Aug 10, 2016 Aug 10, 2016

Copy link to clipboard

Copied

I have a form wih 8 textboxes where user can input numbers. And a total box, auto calculates the values as total as sum.

But i want to restrict the total field as max value is 60.

When the max value exceeds 60, then popup a error saying

"Value should not exceed 60"

and mall fields clear (text1.value="")

Thanks.

TOPICS
Acrobat SDK and JavaScript

Views

1.4K

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

LEGEND , Aug 11, 2016 Aug 11, 2016

The custom calculation script could be something like:

// Custom calculation script for total fields

(function () {

    var sum = 0;

    // Array of input field names

    aFields = ["text1", "text2","text3","text4","text5","text6","text7","text8"];

    // Add up the values of the input fields

    for (var i = 0; i < aFields.length; i += 1) {

        sum += +getField(aFields).value;

    }

    // Set this field value to the sum, unless it's greater than 60

    if (sum <= 60) {

        event.value = sum;

    }

...

Votes

Translate

Translate
LEGEND ,
Aug 10, 2016 Aug 10, 2016

Copy link to clipboard

Copied

and mall fields clear (text1.value="")

Can you clarify what you mean here? Do you want all of the 8 input fields to be cleared, or the calculated field to be cleared?

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 ,
Aug 11, 2016 Aug 11, 2016

Copy link to clipboard

Copied

Thanks for reply.

all 8 text fields to be clear. means text length is equals to zero.

textbox.1value = " "

and also calculated field should be cleared.

hope you got it.

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
LEGEND ,
Aug 11, 2016 Aug 11, 2016

Copy link to clipboard

Copied

The custom calculation script could be something like:

// Custom calculation script for total fields

(function () {

    var sum = 0;

    // Array of input field names

    aFields = ["text1", "text2","text3","text4","text5","text6","text7","text8"];

    // Add up the values of the input fields

    for (var i = 0; i < aFields.length; i += 1) {

        sum += +getField(aFields).value;

    }

    // Set this field value to the sum, unless it's greater than 60

    if (sum <= 60) {

        event.value = sum;

    } else {  // Clear all the fields and alert user

        event.value = "";

        resetForm(aFields);

        app.alert("Error message goes here.", 3);

    }

})();

Set the field names in the aFields array to match the names of the input fields and change the alert text.

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 ,
Aug 11, 2016 Aug 11, 2016

Copy link to clipboard

Copied

thank you.

working. do you help in fixing some error popups always annoying.

tell me your email.

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
LEGEND ,
Aug 11, 2016 Aug 11, 2016

Copy link to clipboard

Copied

If you have a question about something, post it in the appropriate forum here.

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 ,
Aug 12, 2016 Aug 12, 2016

Copy link to clipboard

Copied

Hi, i cannot explain, but i have recorded my desktop and the link is here for the video.

please watch it..

accrobat [send me form back: shekharmine at gmail dot com] - YouTube

Here is my PDF download and modify the script and send me back. thank you..

LRC supervision log for BACB - for editing.pdf - Google Drive

each and every time i am entering to a new cell, it's showing error.

please remove that error.

here is Help Article similar to this:

The value entered does not match the format of the field

thank you.

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
LEGEND ,
Aug 12, 2016 Aug 12, 2016

Copy link to clipboard

Copied

Most of the trouble is caused by the calculated fields that include a numeric division operation where the denominator is zero. Whenever you do a division by a field value, you have to use JavaScript to check if the value of the denominator is zero. When you divide by zero, the result can't be formatted as a finite number, so you see the errors you're getting. This is a common problem, so you should be able to find more help with a search, but post again if you get stuck.

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
LEGEND ,
Aug 11, 2016 Aug 11, 2016

Copy link to clipboard

Copied

It's your form but I think clearing the fields will make this a difficult and annoying form for your users. Consider: the user knows the rule and wants to increase field 1, then decrease field 2. But as soon as they increase field 1, all fields are cleared and they must start again. Also users often do something like this: to decrease 45 to 42, first type 2 giving 425 then remove the 5 giving 42.

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 ,
Aug 11, 2016 Aug 11, 2016

Copy link to clipboard

Copied

Hi.

You don't need a script: select the Total field, go to Properties : Validation and enter a range of value from 0 (zero) to 60.

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 ,
Aug 11, 2016 Aug 11, 2016

Copy link to clipboard

Copied

Hey, you're great. it's working.

but

how to popup a custom error message? like

"Total should be 1 to 60"

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 ,
Aug 16, 2016 Aug 16, 2016

Copy link to clipboard

Copied

LATEST

how to popup a custom error message? like "Total should be 1 to 60"

You need to use JavaScript, you cannot customize a built-in Acrobat message.

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