PDA

View Full Version : Timer Help



CrazyCoder
Dec 8th, 2006, 08:25 PM
:confused: Okay, this should be simple but I'm completely stumped. I have a javascript array and I have a timer. Both work [kinda]. What I need it to do is alert [for testing purposes] each zip code in the array - one every five seconds progressively.

What I get is all 6 alerts at once - every five seconds AND if you get behind on clicking the OK button they keep adding up. If you by chance happen to test this script please be careful.

I'm hoping somebody can LOOK at my script and tell me what I am doing wrong. Please . . . anybody . . . ?



<html>
<head>
<script language="JavaScript" type="text/JavaScript">
<!--
function changeZip(){
var i = 0;
var zipArray = new Array(6);
zipArray[0] = "83651";
zipArray[1] = "83644";
zipArray[2] = "83634";
zipArray[3] = "83701";
zipArray[4] = "83642";
zipArray[5] = "83660";
for (i = 0; i < 5; i++){
if(i > 5){
i = 0;
}
var newZip = "zipcode=" + zipArray[i];
var timer = window.setInterval("changeZip()", 5000);
alert(newZip);
}
}
//-->
</script>
</head>

<body onload="changeZip();">
</body>
</html>

Ancora
Dec 8th, 2006, 08:48 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Any Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">

var zipArray = ["83651","83644","83634","83701","83642","83660"];
var n = 0;

function init(){

if (n == zipArray.length){return}
alert(zipArray[n]);
n++;
setTimeout("init()",5000);
}

onload=init;

</script>
<style type="text/css">



</style>
</head>
<body>

</body>
</html>

CrazyCoder
Dec 8th, 2006, 08:52 PM
You Rock!!!

I just found part of a script that kinda looked like this but I was sooooo far off the mark. Thanks BIGTIME! :thumbsup: