Jump to content
  • 0

ababcock

Question

I have multiple submission forms that need to calculate total hours based on the begin time and end time entered. The script I have entered is:

 

<script>

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

 

var date = document.getElementById('InsertRecordDate_of_Service').value;

if(date == "")

date = "1/1/2011";

var hour = document.getElementById('cbParamVirtual2').value;

if(hour =="")

hour="00";

var minute = document.getElementById('cbParamVirtual3').value;

if(minute == "")

minute = "00";

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

 

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

 

 

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

 

if(hour2 =="")

 

hour2="00";

 

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

 

if(minute2 == "")

 

minute2 = "00";

 

var ampm2 = document.getElementById('cbParamVirtual7').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('InsertRecordTotal_Units').value =  totalmin.toFixed(2);

 

};

 

 

</script>

 

This is working some of the time, but not always, and I don't know what the problem is. I just submitted a record for 6/9/15 11:00 AM to 6/9/15 2:00 PM, and it came up with 185.00 hours.

 

Does anyone know a way to make this work?

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Thanks Jan! I did get it fixed to calculate in hours instead of minutes. I have another question now. For our time sheets, staff will be entering a start time and end time, so I will need the form to calculate the total hours for that time period, but there will be multiple lines/times to calculate. For an example:

 

Date          Start Time          End Time          Total

6/24/15      1:00 PM             2:00 PM             1.00

6/25/15      3:00 PM             7:30 PM             4.50

6/26/15      8:15 AM             5:00 PM             8.75

 

Total Hours 14.25

 

I can get it to calculate the first total, but when I duplicate the script for the second line, it only calculates the second line, not both. Any ideas?

Link to comment
Share on other sites

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...