...

View Full Version : add time to give total time



tsclan
12-13-2004, 05:53 PM
ok picture this
I have 3 rows each having two input boxes in them
[] : []
[] : []
[] : []
On the left hand side the boxes are for entering minutes and on the right, entering seconds
at the bottom there is a total time consisting of three input boxes
[] .[] : []
First one on the left for hours, middle for minutes and far right for seconds.

Mathamatically I take it you need to add all the seconds up then divide that by 60 and and you get the minutes and any remainder is the seconds, then you add the minutes up and divide that by 60 and then those are the hours and any remainders gets added onto the minutes already added via the seconds.

Now How am I able to make the total time = the time of all three times from above without refreshing the page so it updates automatically.

Again thank you for any suggestions or ideas

hemebond
12-13-2004, 10:35 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>48897</title>
</head>
<body>
<form onsubmit="makeTotal();return false;">
<table>
<thead>
<tr>
<th>Minutes</th>
<th>Seconds</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
</tbody>
</table>
<input type="submit">
</form>

<p id="result">
</p>

<script type="text/javascript">
var result = document.getElementById("result");
result.style.display = "none";

function makeTotal()
{
var list = document.getElementsByTagName("form")[0].getElementsByTagName("table")[0].getElementsByTagName("input");
var total = 0;

for(var i = 0; i < list.length; i++)
{
total += (i % 2) ? Number(list[i].value) : Number(list[i].value) * 60;
}

var time = new Date(total * 1000);

result.firstChild.nodeValue = time.getUTCHours() + ":" + time.getUTCMinutes() + ":" + time.getUTCSeconds();
result.style.display = "";
}
</script>
</body>
</html>

tsclan
12-13-2004, 10:54 PM
thank you very much although when I click on submit query i get a error box saying "result.firstChild is null or no object"
and Is it at all posibble to have the total time automatically updating in an inputbox rather than pressing submit all the time

hemebond
12-13-2004, 10:59 PM
thank you very much although when I click on submit query i get a error box saying "result.firstChild is null or no object"That's possibly because you're using Internet Explorer and I code to web standards. I don't know what IE calls the value of text nodes.
Is it at all posibble to have the total time automatically updating in an inputbox rather than pressing submit all the timeYes.
<input type="text" onblur="makeTotal()">

tsclan
12-13-2004, 11:09 PM
Thanks yeah I used it in firefox and it worked fine thanks
although I am not quite sure where I am to put this line of code


<input type="text" onblur="makeTotal()">

I am that Incompetent I know :P

EDIT * WAit No I can figure it out for myself thanks I manged to do it
must have been feeling lazy back then

Willy Duitt
12-14-2004, 01:33 AM
http://www.webdeveloper.com/forum/showthread.php?s=&threadid=51398



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum