04-03-2009, 09:20 PM
|
#4 (permalink)
|
|
The Contributor
Join Date: Feb 2009
Posts: 65
Thanks: 0
|
Try this
HTML Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
var stopcount = 93;
var loopcount = 0;
function myfunc() {
loopcount++;
if (loopcount == stopcount) {
clearTimeout(counter);
loopcount = 0;
}
else {
counter = setTimeout("myfunc();", 1000);
document.getElementById('mycount').innerHTML = loopcount;
}
}
function setval() {
stopcount = document.getElementById('endval').value;
loopcount = 0;
myfunc();
}
</script>
</head>
<body onload="myfunc()">
<div id="mycount"></div>
<form>
<input type="text" id="endval" value="">
<button type="button" onclick="setval()">Click Me</button>
</form>
</body>
</html>
All I did was make the onload event start the function and setup a div to display the results.
Also added an input field to make a it so you can change "stopcount" and run that in the "myfunc" when you click the button
Note that the script is in the <head> tag, that is typically where you place it unless you make a separate file for it.
|
|
|
|