I am trying to add a clock in/clock out function to my database project. I currently have a main form that the employee is directed to upon login. What I would like to accomplish is the ability to insert int the database when the employee clicks the “Clock In” button. (I will need AJAX for this as well, as I don’t want to refresh the page.)
Here is the clock in/clock out area that I am working on:
<table>
<tr><td><name="Date"><script> document.write(new Date().toDateString()); </script></td>
<td width="120"></td><td><input type='button' value='Clock In' onclick='STime()'></td>
<td><input type='hidden' id='ST'><input type='text' name='ArrivalTime' id='Start' style='background: black; color: white; border:0;'></td></tr>
<tr><td colspan="2"></td><td><input type='button' value='Clock Out' onclick='TotalTime()'></td>
<td><input type='hidden' id='ED'><input type='text' name='EndTime' id='End' style='background: black; color: white; border: 0;'></td></tr>
<tr><td colspan="2"></td><td>Daily Time:</td><td><input type='hidden' id='JT'><input type='text' name='ElapsedTime' id= 'JTime' style='background: black; color: white; border:0;'></td></tr>
</table>
I am using a javascript time calculation to calculate the total time that I am also using on a separate page. I am wondering if there is a way to include the insert into inside the javascript function.
<script type='text/javascript'>
function STime() {
var d = new Date();
var n = d.getTime();
var v = d.toLocaleTimeString();
document.getElementById("ST").value = n;
document.getElementById("Start").value = v;
}
function ETime() {
var d = new Date();
var n = d.getTime();
var v = d.toLocaleTimeString();
document.getElementById("ED").value = n;
document.getElementById("End").value = v;
}
function JobTime() {
var StartTime = document.getElementById("ST").value;
var EndTime = document.getElementById("ED").value;
var difference = EndTime-StartTime;
var milliseconds = parseInt((difference % 1000) / 100);
var seconds = Math.floor((difference / 1000) % 60);
var minutes = Math.floor((difference / (1000 * 60)) % 60);
var hours = Math.floor((difference / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
var Total = hours + ":" + minutes;
document.getElementById("JTime").value = Total;
}
function TotalTime() {
ETime();
JobTime();
}
</script>