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

Custom Javascript

New Here ,
Oct 13, 2016 Oct 13, 2016

I have a column labeled "Number of Round Trips" for a monthly mileage report.  Each field is labeled Trips1 through Trips31.  I need to be able to calculate the number of days the vehicle is used.  It would be an easy calculation if there were 30 - round trips and only one - 1/2 trip.  How would one configure the JavaScript so that each 1/2 trip calculates as 1 day?   For example, how can I calculate 27- round trips and 4 - 1/2 trips to be 31 days and not 29 days?

TOPICS
Acrobat SDK and JavaScript , Windows
404
Translate
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 , Oct 13, 2016 Oct 13, 2016

There are different ways you can do that. Can I assume that there is a maximum of one round trip per day?

If so, you could use the following script as your calculation script in your "totals" field:

var cnt = 0;

for (var i=0; i<=31; i++) {

    var f = this.getField("Trips" + i);

    if (f != null) {

        if (Number(f.value) > 0)

            cnt++;

    }

}

event.value = cnt;

This will count anything that is larger than 0 as a day the vehicle was used.

Translate
Community Expert ,
Oct 13, 2016 Oct 13, 2016

There are different ways you can do that. Can I assume that there is a maximum of one round trip per day?

If so, you could use the following script as your calculation script in your "totals" field:

var cnt = 0;

for (var i=0; i<=31; i++) {

    var f = this.getField("Trips" + i);

    if (f != null) {

        if (Number(f.value) > 0)

            cnt++;

    }

}

event.value = cnt;

This will count anything that is larger than 0 as a day the vehicle was used.

Translate
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 ,
Oct 13, 2016 Oct 13, 2016
LATEST

Thank you so very much for taking the time to help me!

It works perfectly☺

Michelle Sylvestre, (Personal/Business information removed. Email signatures and personal information )

Translate
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