This one is not quite polished yet and a lot more complicated, but it gets the job done... I've written a little javascript 'stopwatch' that will automatically fill in the actual test duration. All you have to do is hit the start button at the beginning of executing the test, and hit the stop button when you're done, and it will fill in the time between button pushes into the actual test duration field. here's the code:
three global variables (outside the scope of any functions, at the top of the <script> section of the template):
var startTime;
var endTime;
var flagstop = 0;
the actual function you'll be calling with your new button:
function StartStop()
{
if ( flagstop == 0)
{
startTime = new Date();
var clocktimer = document.getElementById('clock');
clocktimer.value = startTime.getHours()+":"+startTime.getMinutes();
document.TLForm.elements.TL_ACTDURATION_EDIT.value = " ";
var startstop = document.getElementById('startstopbutton');
flagstop = 1;
startstop.value = 'Stop';
return;
}
if ( flagstop == 1)
{
endTime = new Date();
var totalHours = endTime.getHours() - startTime.getHours();
if ( totalHours < 10)
totalHours = "0" + totalHours;
var totalMinutes = endTime.getMinutes() - startTime.getMinutes();
if(totalMinutes < 0)
totalMinutes = 60 + totalminutes;
if( totalMinutes < 10)
totalMinutes = "0" + totalMinutes;
document.TLForm.elements.TL_ACTDURATION_EDIT.value = totalHours+":"+totalMinutes;
flagstop = 0;
var startstop = document.getElementById('startstopbutton');
startstop.value = 'Start';
return;
}
return;
}
in the table where the actual duration is listed, replace:
<td class=TestCaseData><!--TL_ACTDURATION_EDIT--></td>
with:
<td class=TestCaseData><!--TL_ACTDURATION_EDIT--> <input id="clock" type="text" value="00:00" size=3 readonly> <input id="startstopbutton" type=button value="Start" onClick=StartStop()></td>
(add the two input's after the <!--TL_ACTDURATION_EDIT-->)
I'm hoping to figure out why an actual stopwatch won't work here. I tried using someone else's stopwatch code, but I couldn't get it to actually count, so instead it just displays the start time in the clock field.
three global variables (outside the scope of any functions, at the top of the <script> section of the template):
var startTime;
var endTime;
var flagstop = 0;
the actual function you'll be calling with your new button:
function StartStop()
{
if ( flagstop == 0)
{
startTime = new Date();
var clocktimer = document.getElementById('clock');
clocktimer.value = startTime.getHours()+":"+startTime.getMinutes();
document.TLForm.elements.TL_ACTDURATION_EDIT.value = " ";
var startstop = document.getElementById('startstopbutton');
flagstop = 1;
startstop.value = 'Stop';
return;
}
if ( flagstop == 1)
{
endTime = new Date();
var totalHours = endTime.getHours() - startTime.getHours();
if ( totalHours < 10)
totalHours = "0" + totalHours;
var totalMinutes = endTime.getMinutes() - startTime.getMinutes();
if(totalMinutes < 0)
totalMinutes = 60 + totalminutes;
if( totalMinutes < 10)
totalMinutes = "0" + totalMinutes;
document.TLForm.elements.TL_ACTDURATION_EDIT.value = totalHours+":"+totalMinutes;
flagstop = 0;
var startstop = document.getElementById('startstopbutton');
startstop.value = 'Start';
return;
}
return;
}
in the table where the actual duration is listed, replace:
<td class=TestCaseData><!--TL_ACTDURATION_EDIT--></td>
with:
<td class=TestCaseData><!--TL_ACTDURATION_EDIT--> <input id="clock" type="text" value="00:00" size=3 readonly> <input id="startstopbutton" type=button value="Start" onClick=StartStop()></td>
(add the two input's after the <!--TL_ACTDURATION_EDIT-->)
I'm hoping to figure out why an actual stopwatch won't work here. I tried using someone else's stopwatch code, but I couldn't get it to actually count, so instead it just displays the start time in the clock field.
Comment