Click to See Complete Forum and Search --> : incrementing numbers...HELP!!


homeward bound
02-01-2003, 11:37 AM
I’ve been to this forum a loooong time ago, and I managed to get some help. So I’m hoping that somebody here can help me out again. I’m doing a service project for HIV/AIDS victims in Africa, and I need a script that does some number incrementing for the amount of deaths per minute. I don’t know how to do this.

I need a counter that starts at 0 and increases by 6 every minute (to continue until I stop it). The updated result every minute is the only thing I need displayed. This is really important and I don’t know how to do it. Can somebody please help me out?

Thanks so much

SB

Zach Elfers
02-01-2003, 12:46 PM
<script type="text/JavaScript">
<!--
function increment(i) {
document.formName.formField.value = i;
i++;
window.setTimeOut("increment(i);", 1000);
}
//-->
</script>
...
<body onLoad="increment(1);">
...
<form name="formName">
<input type="text" name="fieldName" value="0">
</form>

That should do it. Hope that helps!:)

Vamsee Krishna
02-01-2003, 12:58 PM
Here's the complete code
----------------------------------------------------------------------
<body>
<script language=javascript>
var count=0;
var counterid;
function start()
{
counterid = setTimeout("start()",1000);
count++;
document.forms[0].counter.value = count;
}
function stop()
{
clearTimeout(counterid);
}
</script>
<form>
<table>
<tr><td colspan=2>
<input name=counter value=0>
</td></tr>
<tr>
<td onclick="start()">
<input type=button value=Start>
</td>
<td onclick="stop()">
<input type=button value=Stop>
</td>
</tr>
</table>
</form>
</body>
----------------------------------------------------------------------
Hope it helps....

homeward bound
02-01-2003, 01:01 PM
thanks

SB

Charles
02-01-2003, 01:04 PM
<script type="text/javascript">
<!--
Date.SECOND = 1000;
Date.MINUTE = Date.SECOND * 60;

Date.prototype.elapsedTime = function () {return new Date().getTime() - this.getTime()}

document.write('<form action="" name="clock"><div>AIDS Deaths since start:<br><input type="text" name="time"><br><input type="button" name="start" value="start"><input type="button" name="stop" value="stop"></div></form>');

document.clock.start.onclick = function() {
start = new Date();
id = setInterval('document.clock.time.value = 6 * Math.floor(start.elapsedTime() / Date.SECOND)', 500);
}

document.clock.stop.onclick = function() {clearInterval(id)}
// -->
</script>

Keep in mind that JavaScript doesn't work for one or more in ten users. You need to hide the function for those people.