Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Exit

- Home
- Acrobat SDK
- Discussions
- Override time interval calculation with manual inp...

- Override time interval calculation with manual inp...

0

Override time interval calculation with manual input?

/t5/acrobat-sdk-discussions/override-time-interval-calculation-with-manual-input/td-p/10855716
Jan 14, 2020
Jan 14, 2020

Copy link to clipboard

Copied

*Disclaimer: I know nothing in the way of JavaScript and have had to have help figuring out the scripts mentioned below. *

I'm designing a form that records a rate of movement by having start and end times entered (in text fields formatted as hh:MM t) and having beginning and ending distances entered (as numbers with two decimal places).

For the sake of the example, let:

J=Start distance (feet)

K=End distance (feet)

M=Start time (clock time)

P=End time (clock time)

R=Time Interval (in minutes, calculated using Javascript from P & M)

L=Rate of distance over time (inches per minute), calculated with simplified field notation 12*(K-J)/R.

My problem is that there are times when the person taking the measurements doesn't keep track of the start and end times, uses a stopwatch and therefore only has the time interval R. So I need them to be able to override the calculation in R with manual input.

In plain text, I was trying to do this:

L = 12(K-J) / (P-M)

unless P&M are blank, then

L = 12(K-J) / R

Unless there's a way to edit the code in R to allow me to manually override the calculation in that field. This is the code in R:

```
var cStart = this.getField("startTime").value;
var cStop = this.getField("finishTime").value;
if (cStart != "" && cStop != "") {
var tStart = parseTime(cStart);
var tStop = parseTime(cStop);
var total = (tStop - tStart)/(1000*60);
event.value = (total < 0 ? total += 24 : total);
}
else {
event.value = "";
}
```

That code was borrowed and modified from elsewhere, so other than editing the field names to match the input fields in my form, I don't really know what I'm doing with it.

TOPICS

Acrobat SDK and JavaScript

Community guidelines

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

2
Replies
2

/t5/acrobat-sdk-discussions/override-time-interval-calculation-with-manual-input/m-p/10861672#M8301
Jan 16, 2020
Jan 16, 2020

Copy link to clipboard

Copied

Hi,

If you’ve already assigned the name values to all of your text field objects (as V, K, M, P, R, and L), you can try something like this:

```
//I HAVE NOT TESTED THIS BUT YOU CAN TRY IT OUT AND CORRECT IT
var v = this.getField("V").value;
var k = this.getField("K").value;
var l = this.getField("L").value
var m = this.getField("M").value;
var p = this.getField("P").value;
var r = this.getField("R").value;
var j = this.getField("J").value;
var blank = this.getField("R").valueAsString=+textObject.value;}
if (k !="" && j!="") event.value = ((k-j)*12)/r;
event.value = ((k-j)*12)/blank;
//OR
//custom calc script for field L = 12*(K-J)/R or L = 12(K-J) / (P-M)
//first declare your variables Start distance (feet)
var = this.getField("V").value;
//End distance (feet)
var k = this.getField("K").value;
var l = (this.getField(“L”).value
//Start time (clock time)
var m = this.getField("M").value;
//End time (clock time)
var p = this.getField("P").value;
//Time Interval from Field R
var r = this.getField("R").value;
// the resulting calculation of your script for field L
event.value = ((k – j)*12)/r;
//And This is the custom calculation script for Field R
var cStart = this.getField("M").value;
var cStop = this.getField("P").value;
var l = this.getField("L").value;
//this last variable is necessary to provide the users with a direct manual entry
var r = this.getField("R").valueAsString;
if (cStart != "" && cStop != "") {
var tStart = parseTime(m);
var tStop = parseTime(p);
var total = (tStop - tStart)/(1000*60);
event.value = (total < 0 ? total += 24 : total);
}
else if (cStart =="") && (cStop =="") {
this.getField("R").value=textObject.value;
}
//FOR THE LAST PART IN THIS SCRIPT CHECK IF THIS OTHER LINE BELOW WORK FOR YOU
// I HAVE NOT TESTED IT ON MY END
if(!event.willCommit) {this.getField("R").value=event.value;}
```

Community guidelines

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

Community Expert
,

LATEST
/t5/acrobat-sdk-discussions/override-time-interval-calculation-with-manual-input/m-p/10864098#M8302
Jan 17, 2020
Jan 17, 2020

Copy link to clipboard

Copied

This seems to be a duplicate post from here: https://community.adobe.com/t5/acrobat/how-to-override-a-calculation-with-manual-entry-in-results-fi...

++Adding to Try67’s observation, This rate of distance over time formula is expressed incorrectly and therefore the variables are also declared incorrectly.

In order to come up with a script that will calculate correctly when any of the values in the other fields are changed, this question needs to be rephrased as “How do you find feet per minute with distance and time?

In your case you want to apply this formula like this: What is the rate of movement per every minute measured in feet at a constant speed of feet per minute.

Since 1 Hour = 60 minutes, and 1 minute = 60 seconds, and 1 foot = 12 inchesWe will need to consider how to convert seconds to minutes and minutes to hour, and also if the feet per distance involved a few feet per minute with a few inches when the time stopped.

If this is not important to consider and you’re ok with rounding a result then disregard

But, what is confusing to me in your equation is that you’re multiplying by 12 instead which gives you a total in inches, not feet. To get the exact measurement in feet, shouldn’t it be divided by 12 and then convert to feet? would that make more sense?

So, the formula rate of movement is rate = distance / time OR, in your case rate = feet/minutes. And here is the other confusing part. Where do you get a start distance from ? How can you input a starting distance if you haven’t started time yet to measure how an object traveled from point A to point B.

The way your equation is expressed as of yet, would only make more sense if you were using some sort of map grid, and then calculate your travel with a starting coordinate to represent point A and another coordinate to represent Point B.

Unless you are all of the following formulas together (1) **rate equals distance divided by time: r = d/t **and be able to resolve for **(2) distance** (which is rate of movement multiplied by time **(d = rt)** ) and / or get the missing starting time from the end time using **(3) **distance divided by rate of movement **(t = d/r)** nothing at this point is helping me understand.

Community guidelines

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

Copyright © 2024 Adobe. All rights reserved.