How to override a calculation with manual entry in results field
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. There are functions going on here that I don't fully understand, I just know that chunk of code does the calculation I need it to. I just need to be able to override it and allow manual entry of time elapsed in place of start/end time for situations when start and end time is unknown but elapsed time isn't.
