...

View Full Version : adding time



t_ravichandu
05-07-2004, 01:17 PM
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

glenngv
05-07-2004, 01:54 PM
<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum