Click here to Skip to main content
16,017,617 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<script type="text/javascript">
       function updateValuel() {
           var val1 = document.getElementById("<%=(txtday1hrs).ClientID%>").value;
           var val2 = document.getElementById("<%=(txtday2hrs).ClientID%>").value;
           var val3 = document.getElementById("<%=(txtday3hrs).ClientID%>").value;
           var val4 = document.getElementById("<%=(txtday4hrs).ClientID%>").value;
           var val5 = document.getElementById("<%=(txtday5hrs).ClientID%>").value;
           var val6 = document.getElementById("<%=(txtday6hrs).ClientID%>").value;
           var val7 = document.getElementById("<%=(txtday7hrs).ClientID%>").value;
           document.getElementById("<%=(lbltothrsedit).ClientID%>").innerHTML = ((parseFloat(val1) + parseFloat(val2) + parseFloat(val3) + parseFloat(val4) + parseFloat(val5) + parseFloat(val6) + parseFloat(val7)) || 0).toString();
          
       }
   </script>

i want to calculate the above textbox values interms of time like HH:mm how can i do that plz help me.....
Posted

1 solution

Hi member, before appending it to the lbltothrsedit
add all those val1 to val7 values and just do this statements

C#
var tick = 7512
var hrs = Math.floor(tick/3600);
var mins = Math.floor((tick % 3600)/60);
var secs = tick % 60;
var tock = (hrs < 10 ? "0" : "" ) + hrs + ":" 
         + (mins < 10 ? "0" : "" ) + mins + ":" 
         + (secs < 10 ? "0" : "" ) + secs;


or this way also
C#
var tick = 7512
var hrs = Math.floor(tick/3600);
tick = tick - 3600 * hrs;
var mins = Math.floor(tick/60);
tick = tick - 60 * mins;
var secs = tick;
var tock = (hrs < 10 ? "0" : "" ) + hrs + ":"
         + (mins < 10 ? "0" : "" ) + mins + ":"
         + (secs < 10 ? "0" : "" ) + secs;


or this way also

C#
var tick = 7512
var secs = tick % 60;
tick = ( tick - secs ) / 60;
var mins = tick % 60;
tick = ( tick - mins ) / 60;
var hrs = tick;
var tock = (hrs < 10 ? "0" : "" ) + hrs + ":"
         + (mins < 10 ? "0" : "" ) + mins + ":"
         + (secs < 10 ? "0" : "" ) + secs;




I haven't tried running the code, just check it and let us know if u r facing any issues after working on this part of code.

Thanks
Ganesh
 
Share this answer
 
Comments
Member 10057465 30-Sep-13 10:47am    
Thanx for quick reply
but how do i do that.. iam adding val1 to val7 values to a variable like var add=va1 to val7
and then i have to add these to var tock like var tock=add+(hrs < 10 ? "0" : "" ) + hrs + ":" + (mins < 10 ? "0" : "" ) + mins + ":"+ (secs < 10 ? "0" : "" ) + secs;
plz dont mind i am new to javascript please help me..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900