Subtract two times and display the result in third textbox automatically

Here we are adding zero hours if the time is AM and 12 hours if the time is PM. for instance 1:00PM is, as you know, 1+12=13 hours. The whole formula takes values from the various input elements, turns them into minutes, and then uses the minutes for the start time and then end time to calculate the elapsed time.
60 x ( number of hours + 0 or 12 hours depending on AM or PM) + number of minutes.

The F is a short cut to the form holding all of the input elements. F=document.ff2;
F[am_pm].value reads the value from the form using the am_pm variable passed by the function getTime(), which in turn has been passed by the function calc(). The sequence of events for the start time am_pm component is:
totStartMin=getTime("startAmpm", ........
getTime(am_pm, ........
Number(F[am_pm].value)
The startAmpm variable is the name of the start AM-PM radio button pair for the start time in the form.

2 Likes