Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Timer Help

  1. #1
    New Coder
    Join Date
    Sep 2006
    Location
    USA
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Timer Help

    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 . . . ?

    Code:
    <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>
    • Jesus called. He says He misses you.

  • #2
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Code:
    <!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>

  • #3
    New Coder
    Join Date
    Sep 2006
    Location
    USA
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You Rock!!!

    I just found part of a script that kinda looked like this but I was sooooo far off the mark. Thanks BIGTIME!
    • Jesus called. He says He misses you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •