Jump to content
  • 0

Blocking Time Entries Over 12 Hours


ababcock

Question

I have a time sheet submission page where users enter their start and end times, and the system calculates their total hours. I'm trying to find a way to block them from entering spans of time greater than 12 hours because this is usually an error in AM/PM selection. I'm hoping to have a pop-up that tells them there is an error they need to fix before they can submit it. Is there a way to do this? Below is what I have in my footer to calculate the time:

<script>

document.getElementById('Submit').onmouseover = function(){

var date = document.getElementById('InsertRecordDate').value;
if(date == "")
date = "1/1/2011";
var hour = document.getElementById('cbParamVirtual1').value;
if(hour =="")
hour="00";
var minute = document.getElementById('cbParamVirtual2').value;
if(minute == "")
minute = "00";
var ampm = document.getElementById('cbParamVirtual3').value;

document.getElementById('InsertRecordStart_Time').value = date + " " + hour + ":" + minute + " " + ampm;


var hour2 = document.getElementById('cbParamVirtual4').value;

if(hour2 =="")

hour2="00";

var minute2 = document.getElementById('cbParamVirtual5').value;

if(minute2 == "")

minute2 = "00";

var ampm2 = document.getElementById('cbParamVirtual6').value;

document.getElementById('InsertRecordEnd_Time').value = date + " " + hour2 + ":" + minute2 + " " + ampm2;
var start= new Date(document.getElementById('InsertRecordStart_Time').value);
var end = new Date(document.getElementById('InsertRecordEnd_Time').value);
var timeDiff = end - start;
var hh = Math.floor(timeDiff / 1000 / 60 / 60);

timeDiff -= hh * 1000 * 60 * 60;

var mm = Math.floor(timeDiff / 1000 / 60);

var totalmin= (mm+ (hh * 60)) ;
document.getElementById('InsertRecordHours').value =  (totalmin/60).toFixed(2);

};


</script>

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...