Hi,
I'm very new to javascript and have very little background knowledge. For some reason I can't get the script to work. It uses IF statements but for some starnge reason, it skips and ignore the variable?? named "total" and hence the IF statements don't work.
I have a onChange handler on the tmsht_mon_out field, which I'm hoping would correctly display the values for the other fields based on the IF statements.
This is for a timesheet, in which the user enters the time they come in and they time they go out, and then the total hours are computed. Anything over 8 hours goes into time and half (time_mon_oneha lf) and anything over 3 hours in time_mon_onehal f (or 11 hours total) will go into tmsht_mon_doubl e.
Hope someone could help me!.. please.
[CODE=javascript]
<script type="text/javascript">
function overtime() {
var t1 = document.getEle mentById("tmsht _mon_out").valu e
var t2 = document.getEle mentById("tmsht _mon_in").value ;
var m = (t1.substring(0 ,t1.indexOf(':' ))-0) * 60 + (t1.substring(t 1.indexOf(':')+ 1,t1.length)-0) - (t2.substring(0 ,t2.indexOf(':' ))-0) * 60 + (t2.substring(t 2.indexOf(':')+ 1,t2.length)-0);
var h = Math.floor(m / 60);
var total = (h + ':' + (m - (h * 60)));
document.getEle mentById("tmsht _mon_total").va lue = total;
if (total <= 11)
{
document.getEle mentById("tmsht _mon_ord").valu e = 8;
document.getEle mentById("time_ mon_onehalf").v alue = (total - 8).toFixed(2);
}
else if (total > 11.0)
{
document.getEle mentById("tmsht _mon_ord").valu e = 8;
document.getEle mentById("time_ mon_onehalf").v alue = 3;
document.getEle mentById("tmsht _mon_double").v alue = (total - 11).toFixed(2);
}
else
{
document.getEle mentById("tmsht _mon_total").va lue = total;
document.getEle mentById("tmsht _mon_ord").valu e='';
document.getEle mentById("time_ mon_onehalf").v alue='';
document.getEle mentById("tmsht _mon_double").v alue ='';
}
}
</script>
[/CODE]
I'm very new to javascript and have very little background knowledge. For some reason I can't get the script to work. It uses IF statements but for some starnge reason, it skips and ignore the variable?? named "total" and hence the IF statements don't work.
I have a onChange handler on the tmsht_mon_out field, which I'm hoping would correctly display the values for the other fields based on the IF statements.
This is for a timesheet, in which the user enters the time they come in and they time they go out, and then the total hours are computed. Anything over 8 hours goes into time and half (time_mon_oneha lf) and anything over 3 hours in time_mon_onehal f (or 11 hours total) will go into tmsht_mon_doubl e.
Hope someone could help me!.. please.
[CODE=javascript]
<script type="text/javascript">
function overtime() {
var t1 = document.getEle mentById("tmsht _mon_out").valu e
var t2 = document.getEle mentById("tmsht _mon_in").value ;
var m = (t1.substring(0 ,t1.indexOf(':' ))-0) * 60 + (t1.substring(t 1.indexOf(':')+ 1,t1.length)-0) - (t2.substring(0 ,t2.indexOf(':' ))-0) * 60 + (t2.substring(t 2.indexOf(':')+ 1,t2.length)-0);
var h = Math.floor(m / 60);
var total = (h + ':' + (m - (h * 60)));
document.getEle mentById("tmsht _mon_total").va lue = total;
if (total <= 11)
{
document.getEle mentById("tmsht _mon_ord").valu e = 8;
document.getEle mentById("time_ mon_onehalf").v alue = (total - 8).toFixed(2);
}
else if (total > 11.0)
{
document.getEle mentById("tmsht _mon_ord").valu e = 8;
document.getEle mentById("time_ mon_onehalf").v alue = 3;
document.getEle mentById("tmsht _mon_double").v alue = (total - 11).toFixed(2);
}
else
{
document.getEle mentById("tmsht _mon_total").va lue = total;
document.getEle mentById("tmsht _mon_ord").valu e='';
document.getEle mentById("time_ mon_onehalf").v alue='';
document.getEle mentById("tmsht _mon_double").v alue ='';
}
}
</script>
[/CODE]
Comment