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

Thread: adding time

  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    adding time

    adding time
    hi,
    I have 3 text boxes;User enters time in the format hh.mm(1.24 means 1 hr 24 min). I need to add the 3 times and display the total in another text box.
    Please give me some idea of how to work in javascript
    cheers
    chandu

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    <script type="text/javascript">
    function calculateTime(){
      var hrTotal=0,minTotal=0,hr,min;
      for (var i=0;i<arguments.length;i++){
         arr = arguments[i].split('.');
         if (arr.length==2){
            hr = Number(arr[0],10);
            min = Number(arr[1],10);
            if (!isNaN(hr) && !isNaN(min)){
               hrTotal += hr;
               minTotal += min;
            }
         }     
      }
      hrTotal += Math.round(minTotal/60);
      minTotal = minTotal%60;
      return hrTotal+"."+minTotal;
    }
    
    var t = calculateTime('1.24','1.56','1.30');
    alert(t);
    </script>


  •  

    Posting Permissions

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