Jump to content

Time counter issue


naveendk.55

Recommended Posts

Hi,

 

I have added a time counter in below code. This is used to track the total time of a project. If a person is going on break, then they will apply the break that stops the time counter. However, once they come back from break and end the break, then time is counting at double speed (two seconds instead at one second).  Any help please....

 

 


<html> 
<head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title>Strategy One - Tracker</title>

    <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    <!--[if IE 6]><link rel="stylesheet" href="style.ie6.css" type="text/css" media="screen" /><![endif]-->
    <!--[if IE 7]><link rel="stylesheet" href="style.ie7.css" type="text/css" media="screen" /><![endif]-->



<!-- Script for Current time in text box -->
<script type="text/javascript">
function GetDate()
{
var curDateTime = new Date()
var curHour = curDateTime.getHours()
var curMin = curDateTime.getMinutes()
if(curHour<10) curHour = "0" + curHour
  	if(curMin<10) curMin = "0" + curMin


document.getElementById('start_time').value = curHour + ":" + curMin; 
var row = document.getElementById("end1_time");
var row1 = document.getElementById("start1_time");
        row.style.display = 'none';
	 row1.style.display = 'none';

}
</script>
<!-- End of Script for Current time in text box -->
<!-- Script for Current time in text box -->
<script type="text/javascript">
function GetDate1()
{
var curDateTime = new Date()
var curHour = curDateTime.getHours()
var curMin = curDateTime.getMinutes()
  	if(curHour<10) curHour = "0" + curHour
  	if(curMin<10) curMin = "0" + curMin
document.getElementById('end_time').value = curHour + ":" + curMin;

var row = document.getElementById("start1_time");
var row1 = document.getElementById("end1_time");
var row2 = document.getElementById("start2_time");
var row3 = document.getElementById("end2_time");
	row.style.display = 'none';
	row1.style.display = 'none';
	row2.style.display = 'none';
	row3.style.display = 'none';

}
</script>

<script type="text/javascript">
function GetDate2()
{
var curDateTime = new Date()
var curHour = curDateTime.getHours()
var curMin = curDateTime.getMinutes()
  	if(curHour<10) curHour = "0" + curHour
  	if(curMin<10) curMin = "0" + curMin
document.getElementById('break_time_out').value = curHour + ":" + curMin ;
var row = document.getElementById("end2_time");
        row.style.display = '';
}
</script>
<script type="text/javascript">
function GetDate3()
{
var curDateTime = new Date()
var curHour = curDateTime.getHours()
var curMin = curDateTime.getMinutes()

  	if(curHour<10) curHour = "0" + curHour
  	if(curMin<10) curMin = "0" + curMin


document.getElementById('break_time_in').value = curHour + ":" + curMin ;

}
</script>



<script type="text/javascript">
function tout1()
{
var temp= document.tracker.start_time.value;

if(temp.length>0)
{
var row1 = document.getElementById("end1_time");
var row2 = document.getElementById("start2_time");
        row1.style.display = 'none';
        row2.style.display = 'none';

}
else
{
var row = document.getElementById("start1_time");
var row1 = document.getElementById("end1_time");
var row2 = document.getElementById("start2_time");
        row.style.display = 'none';
	row1.style.display = 'none';
	row2.style.display = 'none';
}
}

function tout2()
{
var temp= document.tracker.start_time.value;

if(temp.length>0)
{
var row = document.getElementById("start1_time");
var row1 = document.getElementById("end1_time");
var row2 = document.getElementById("start2_time");
var row3 = document.getElementById("end2_time");
	row.style.display = 'none';
	row1.style.display = 'none';
	row2.style.display = 'none';
	row3.style.display = 'none';
}
else
{
var row = document.getElementById("start1_time");
var row1 = document.getElementById("end1_time");
var row2 = document.getElementById("start2_time");
var row3 = document.getElementById("end2_time");
        row.style.display = '';
	row1.style.display = 'none';
	row2.style.display = 'none';
	row3.style.display = 'none';
}
}


</script> 

<script type="text/javascript">
var seconds = 0;
            var minutes = 0;
            var hours   = 0;

            function zeroPad(time) {
                var numZeropad = time + '';
                while(numZeropad.length < 2) {
                    numZeropad = "0" + numZeropad;
                }
                return numZeropad;
            }
            
            function countSecs() {
                 var j=document.tracker.hide.value;
                 if(j=="yes")
                 {
                seconds++;

                if (seconds > 59) {
                    minutes++;
                    seconds = 0;
                }
                if (minutes > 59)
                {
                    hours++
                    minutes = 0;
                                
                }
                document.tracker.time_utilization.value = zeroPad(hours) + ":" + zeroPad(minutes) + ":" + zeroPad(seconds);
                 }
                 else
                     {}
            }

            function startTimer()
            {
                
                action = window.setInterval(countSecs,1000);
                
            }
           
function s()
{
    
    document.tracker.hide.value ="yes";
    startTimer();
    
}

function p()
{
    document.tracker.hide.value ="no";
   
    
}
</script>

</head>
<body>

                                            
			<form name="tracker" method="post" action="processor.php" onsubmit="return formCheck(this);">




			<label class="formFieldQuestion">Start Time *</label><input readonly class=mainForm type=text name=start_time id=start_time size='30' value=''>      
			<input type="button" id="start1_time" style="width: 100px" Value="Start Time" onClick="javascript:GetDate();s();"></li>

              
			<label class="formFieldQuestion">End Time *</label><input readonly class=mainForm type=text name=end_time id=end_time size='30' value='' >     
			<input type="button" id="end1_time" style="width: 100px" Value="End Time" onClick="javascript:GetDate1(); p();" style='display: none'></li>	

			<input type="hidden" name="hide" />


			<label class="formFieldQuestion">Break Time Out </label><input class=mainForm readonly type=text name=break_time_out id=break_time_out size='30' value='' >     
			<input type="button" id="start2_time" style="width: 100px" Value="Start Time" onClick="javascript:GetDate2();tout1();p();"></li>		


			<label class="formFieldQuestion">Break Time In </label><input class=mainForm readonly type=text name=break_time_in id=break_time_in size='30' value=''>     
			<input type="button" id="end2_time" style="width: 100px" Value="End Time" onClick="javascript:GetDate3(); tout2();s();" style='display: none'></li>		


			<label class="formFieldQuestion">Time Utilization</label><input class=mainForm type=text  name=time_utilization id=time_utilization size='30' value='' readonly></li>
				<br /> <br />

				<input id="saveForm" class="mainForm" type="submit" value="Submit"  style="width : 100px"/>


			</form>				

                                            
    
</body>

</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.