Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Timesheet Program

    I wrote about this script a couple weeks ago. I stopped working on it, and just got on it today. Question, what's the easiest way to have it so Monday, tuesday, Wednesday, etc and then the total amount of hours gets added.



    Code:
    <html>
    <head>
    
    <script language="JavaScript" src="gen_validatorv5-.js"
        type="text/javascript" xml:space="preserve"></script>
    <script type="text/javascript">
    
    	function calc(nForm){	
    	
    	
    		
    
    		var inHour =parseInt( nForm.inHr.value)
    		var inMinutes = parseInt( nForm.inMin.value);
    		var lunchOutHour = parseInt(nForm.lunchOutHr.value);
    		var lunchOutMinutes = parseInt( nForm.lunchOutMin.value);
    		var lunchInHour = parseInt( nForm.lunchInHr.value);
    		var lunchInMinutes = parseInt( nForm.lunchInMin.value);
    		var outHour = parseInt( nForm.outHr.value);
    		var outMinutes = parseInt( nForm.outMin.value);
    		
    		var linearInTime = 60*(inHour)+(inMinutes);
    		var linearLunchOutTime = 60*(lunchOutHour)+(lunchOutMinutes);
    		var linearLunchInTime = 60*(lunchInHour)+(lunchInMinutes);
    		var linearOutTime = 60*(outHour)+(outMinutes);
    		
    		
    
    		var workDay = linearOutTime-linearInTime;
    		var lunchPeriod = linearLunchInTime-linearLunchOutTime;
    		var linearMinutesWorked = workDay-lunchPeriod;
    
    		var hoursWorked = parseInt(linearMinutesWorked/60);
    		var minutesWorked = linearMinutesWorked-(hoursWorked*60)
    		
    		if (hoursWorked < 10){hoursWorked = "0"+hoursWorked}
    		if (minutesWorked < 10){minutesWorked = "0"+minutesWorked}		
    
    		nForm.timeWorked.value = hoursWorked+":"+minutesWorked;
    	}
    	
    
    
    </script>
    </head>
    <body>
    
    <div align="center">
      <h1>
        <script src='scripts/gen_validatorv5.js' type='text/javascript'></script>
        <script src='scripts/sfm_moveable_popup.js' type='text/javascript'></script>
        
        <style type='text/css'>
    .error_strings
    {
        font-family:Verdana;
        font-size:10px;
        color:#660000;
    }
    .sfm_float_error_box
    {
        position:absolute;
        z-index:999;
        cursor:default;
        font-family:Verdana;
        font-size:10px;
        color:#660000;
        background-color:#ffff66;
        border-style:solid;
        border-width:1px;
        border-color:#660000;
    }
    .sfm_float_box_td
    {
        padding:3px;
        cursor:default;
        font-family:Verdana;
        font-size:10px;
        color:#660000;
        background-color:#ffff66;
    }
    .sfm_close_box
    {
        font-family:Verdana;
        font-size:10px;
        font-weight:bold;
        color:#ffffff;
        background-color:#660000;
        border-width:0px;
        text-align:center;
    }
    .sfm_cr_box
    {
        font-family:Verdana;
        font-size:10px;
        color:#888888;
        border-style:solid;
        border-width:0px;
        border-color:#660000;
    }
    .sfm_cr_box a
    {
        color:#888888;
    }
      </style>
        Masquerade Timesheet Entry</h1>
    </div>
    <div id='timeSheet_errorloc' class='error_strings' style=''></div>
    
    
    <form name='timeSheet'>
    <table width="833" height="244" border="1" align="center">
      <tr>
        <td width="266"><p align="left">Monday :</p>
          Clock In:
            <label>
            <input name="inHr" type="text" id="inHr" size="10" maxlength="2">
            </label>
    &nbsp
    <label>
    <input name="inMin" type="text" id="inMin" size="10" maxlength="2">
    </label>
    <br>
    Lunch Out:
    <label>
    <input name="lunchOutHr" type="text" id="lunchOutHr" size="10" maxlength="2">
    </label>
    &nbsp
    <label></label>
    <input name="lunchOutMin" type="text" id="lunchOutMin" size="10" maxlength="2">
    <br>
    Lunch In:
    <label>
    <input name="lunchInHr" type="text" id="lunchInHr" size="10" maxlength="2">
    </label>
    &nbsp
    <label>
    <input name="lunchInMin" type="text" id="lunchInMin" size="10" maxlength="2">
    </label>
    <br>
    Clock Out:
    <label>
    <input name="outHr" type="text" id="outHr" size="10" maxlength="2">
    </label>
    &nbsp
    <label>
    <input name="outMin" type="text" id="outMin" size="10" maxlength="2">
    </label>
    <p>Time Worked:
      <input type='text' name='timeWorked' size='5' readonly>
    </p></td>
        <td width="269"><p>Tuesday:</p>
          <p>Clock In:
            <label>
              <input name="inHr2" type="text" id="inHr2" size="10" maxlength="2">
              </label>
      &nbsp
      <label>
      <input name="inMin2" type="text" id="inMin2" size="10" maxlength="2">
      </label>
      <br>
            Lunch Out:
      <label>
      <input name="lunchOutHr2" type="text" id="lunchOutHr2" size="10" maxlength="2">
      </label>
      &nbsp
      <label></label>
      <input name="lunchOutMin2" type="text" id="lunchOutMin2" size="10" maxlength="2">
      <br>
            Lunch In:
      <label>
      <input name="lunchInHr2" type="text" id="lunchInHr2" size="10" maxlength="2">
      </label>
      &nbsp
      <label>
      <input name="lunchInMin2" type="text" id="lunchInMin2" size="10" maxlength="2">
      </label>
      <br>
            Clock Out:
      <label>
      <input name="outHr2" type="text" id="outHr2" size="10" maxlength="2">
      </label>
      &nbsp
      <label>
      <input name="outMin2" type="text" id="outMin2" size="10" maxlength="2">
      </label>
          </p>
          <p>Time Worked:
            <input type='text' name='timeWorked2' size='5' readonly>
          </p></td>
        <td width="276"><p>Wednesday:</p>
          <p>Clock In:
            <label>
              <input name="inHr3" type="text" id="inHr3" size="10" maxlength="2">
              </label>
      &nbsp
      <label>
      <input name="inMin3" type="text" id="inMin3" size="10" maxlength="2">
      </label>
      <br>
            Lunch Out:
      <label>
      <input name="lunchOutHr3" type="text" id="lunchOutHr3" size="10" maxlength="2">
      </label>
      &nbsp
      <label></label>
      <input name="lunchOutMin3" type="text" id="lunchOutMin3" size="10" maxlength="2">
      <br>
            Lunch In:
      <label>
      <input name="lunchInHr3" type="text" id="lunchInHr3" size="10" maxlength="2">
      </label>
      &nbsp
      <label>
      <input name="lunchInMin3" type="text" id="lunchInMin3" size="10" maxlength="2">
      </label>
      <br>
            Clock Out:
      <label>
      <input name="outHr3" type="text" id="outHr3" size="10" maxlength="2">
      </label>
      &nbsp
      <label>
      <input name="outMin3" type="text" id="outMin3" size="10" maxlength="2">
      </label>
          </p>
          <p>Time Worked:
            <input type='text' name='timeWorked3' size='5' readonly>
          </p></td>
      </tr>
      <tr>
        <td><p>Thursday:</p>
          <p>Clock In:
            <label>
              <input name="inHr4" type="text" id="inHr4" size="10" maxlength="2">
              </label>
      &nbsp
      <label>
      <input name="inMin4" type="text" id="inMin4" size="10" maxlength="2">
      </label>
      <br>
            Lunch Out:
      <label>
      <input name="lunchOutHr4" type="text" id="lunchOutHr4" size="10" maxlength="2">
      </label>
      &nbsp
      <label></label>
      <input name="lunchOutMin4" type="text" id="lunchOutMin4" size="10" maxlength="2">
      <br>
            Lunch In:
      <label>
      <input name="lunchInHr4" type="text" id="lunchInHr4" size="10" maxlength="2">
      </label>
      &nbsp
      <label>
      <input name="lunchInMin4" type="text" id="lunchInMin4" size="10" maxlength="2">
      </label>
      <br>
            Clock Out:
      <label>
      <input name="outHr4" type="text" id="outHr4" size="10" maxlength="2">
      </label>
      &nbsp
      <label>
      <input name="outMin4" type="text" id="outMin4" size="10" maxlength="2">
      </label>
          </p>
          <p>Time Worked:
            <input type='text' name='timeWorked4' size='5' readonly>
          </p></td>
        <td><p>Friday:</p>
          <p>Clock In:
            <label>
              <input name="inHr5" type="text" id="inHr5" size="10" maxlength="2">
              </label>
      &nbsp
      <label>
      <input name="inMin5" type="text" id="inMin5" size="10" maxlength="2">
      </label>
      <br>
            Lunch Out:
      <label>
      <input name="lunchOutHr5" type="text" id="lunchOutHr5" size="10" maxlength="2">
      </label>
      &nbsp
      <label></label>
      <input name="lunchOutMin5" type="text" id="lunchOutMin5" size="10" maxlength="2">
      <br>
            Lunch In:
      <label>
      <input name="lunchInHr5" type="text" id="lunchInHr5" size="10" maxlength="2">
      </label>
      &nbsp
      <label>
      <input name="lunchInMin5" type="text" id="lunchInMin5" size="10" maxlength="2">
      </label>
      <br>
            Clock Out:
      <label>
      <input name="outHr5" type="text" id="outHr5" size="10" maxlength="2">
      </label>
      &nbsp
      <label>
      <input name="outMin5" type="text" id="outMin5" size="10" maxlength="2">
      </label>
          </p>
          <p>Time Worked:
            <input type='text' name='timeWorked5' size='5' readonly>
          </p></td>
        <td><div align="left">
          <p>
            <input type='button' value="Calculate" onClick="calc(this.form)">
            <input type="button" name="reset_form" value="Clear Forms" onClick="this.form.reset();">
          </p>
          <p>Total Time Worked:
            <input type="text" name="totalhr" id="totalhr">
          </p>
          <label></label>
        </div></td>
      </tr>
    </table>
    <p align="left">&nbsp; </P>
    <p align="left">&nbsp;</P>
    <p align="left">&nbsp;</P>
    <p align="left">&nbsp;</P>
    <p><br>
        <br>
        <br>
        <br>
    </p>
    </form
    
    
    ><p>&nbsp;</p>
    <p>&nbsp;</p>
    </body>
    </html>

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    from what I can tell, if you change all your parseInt() to Number() you should get a result.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •