Forum Moderators: open
<script type="text/javascript">
function calculate(arg) {
//AM
in_ = arg.am_in.value;
out_ = arg.am_out.value;
in_ampm = in_.substring(in_.length-2);
in_minute = (in_.substring((in_.length-4),3) * 1);
in_hour = (in_.substring(0,(in_.length-4)) * 1) + (in_ampm=="pm"?12:0);
out_ampm = out_.substring(out_.length-2);
out_minute = (out_.substring((out_.length-4),3) * 1);
out_hour = (out_.substring(0,(out_.length-4)) * 1) + (out_ampm=="pm"?12:0);
foobar = new Date();
in_timeObject = new Date(foobar.setHours(in_hour));
in_timeObject = in_timeObject.setMinutes(in_minute);
// in_timeObject is now a Unix timestamp
// let's do the same with the out time
out_timeObject = new Date(foobar.setHours(out_hour));
out_timeObject = out_timeObject.setMinutes(out_minute);
// now you just need to subtract...
timeDiff = (out_timeObject - in_timeObject)/1000;
// timeDiff holds the difference (in seconds) between the "in" and "out" times
time = timeDiff / 60 / 60;
//PM
p_in_ = arg.pm_in.value;
p_out_ = arg.pm_out.value;
p_in_ampm = p_in_.substring(p_in_.length-2);
p_in_minute = (p_in_.substring((p_in_.length-4),3) * 1);
p_in_hour = (p_in_.substring(0,(p_in_.length-4)) * 1) + (p_in_ampm=="pm"?12:0);
p_out_ampm = p_out_.substring(p_out_.length-2);
p_out_minute = (p_out_.substring((p_out_.length-4),3) * 1);
p_out_hour = (p_out_.substring(0,(p_out_.length-4)) * 1) + (p_out_ampm=="pm"?12:0);
foobar = new Date();
p_in_timeObject = new Date(foobar.setHours(p_in_hour));
p_in_timeObject = p_in_timeObject.setMinutes(p_in_minute);
// in_timeObject is now a Unix timestamp
// let's do the same with the out time
p_out_timeObject = new Date(foobar.setHours(p_out_hour));
p_out_timeObject = p_out_timeObject.setMinutes(p_out_minute);
// now you just need to subtract...
p_timeDiff = (p_out_timeObject - p_in_timeObject)/1000;
// timeDiff holds the difference (in seconds) between the "in" and "out" times
p_time = p_timeDiff / 60 / 60;
//TOTAL
arg.expr.value = time
arg.p_expr.value = p_time
arg.total.value = eval((time)+(p_time))
}
</script>
Now, i have this script. What i need to accomplish now is applying this script to 7 days a week for about 50 employees. I'm going to use a form to let someone select each employees name, which will show a new <div> with another form to enter their punch-clock times, and after all the employees time fields are filled out, clicking a button will print out a sheet with each employee's name and their total hours next to it. This is my first JavaScript script, though, so i'm having difficulty figuring out the best way to go about applying this script that i have for over 50 employees, 7 times each... any thoughts to guide me?