View Full Version : Need help with timer

05-04-2006, 10:56 PM
I need help in the time. i have a script that generated random images, but i need it that some how it does it my timer and not randomaly it should do it one after another. here is what i got Could some one please help.



<script language="Javascript">
var images = new Array()
images[0] = 'glass.jpg'
images[1] = 'ball.jpg'
images[2] = '123.jpg'

var k = images.length;
var buff = new Array()
for (i = 0; i < k; i++){
buff[i] = new Image()
buff[i].src = images[i]

var theImage = Math.round(Math.random()*(k-1));

function imagesAppear(){
document.write('<td height="65" valign="top" cellpadding="2">')
document.write('<img src="'+images[theImage]+'">');


<script type="text/javascript" language="javascript">


05-06-2006, 01:05 PM

<title>Image Swap</title>
<script type="text/javascript">
var images=new Array()

var current_image=0;

function imageSwap(){


<img name="picture" src="some_image.jpg" alt="some_image.jpg">
<input type="button" name="start" value="start" onclick="imageSwap();">


Thats just an example, but you can change the '2000' in the setTimeout to whatever you want it. 2000 means the image will rotate every 2 seconds, 5000 would be 5 seconds, etc... It can handle more pictures, all you have to do is add them to the array.

05-06-2006, 01:07 PM
you can also change the line 'current_image=current_image+1' to "current_image++" it means the same thing just a shorter way to do it.

05-07-2006, 03:53 AM
thanks i already found the answser, now i need a help in something else it is posted here http://www.codingforums.com/showthread.php?t=86077.

It would be highly appciated if you could help.

Thanks again,

05-07-2006, 04:16 AM
I think some one should close this, besides you could always thank the people that helped you.

05-07-2006, 10:13 AM
I already replied to that thread.

05-08-2006, 01:44 AM

if you are not looking i already thanked boxxer03. i did not quote but i was saying thanks to him. People like you create problem in the forums.

thanks i already found the answser, now i need a help in something else it is posted here http://www.codingforums.com/showthread.php?t=86077.

It would be highly appciated if you could help.

Thanks again,

boxxer03 thanks for you help, but i was unable to find a way to realate a to the image on the internet. If you know anyother way or if you know that any way to do it by asp it will be higly appreciated.


05-08-2006, 03:39 AM
You can definetly do it. But it will be an excessive code because the problem you will have with relating pictures to dates is that if you have 5 pictures on the 6th day it needs to know to reset and since months stagger from 30-31 days and 28-29 (leap year) in February it creates a problem. So basically you would need a code that "knows" how many days are in each month and can break the month down and then assign a picture to each date and at the end of the month it also has to go from say image3 on the 31st of one month to image4 on the 1st of the next month instead of resetting for the month, but like I said it can be done, but it would be very time consuming and a large script. Your best bet would be to stick with using a timer to rotate the images periodically. :)

05-08-2006, 03:41 PM

Can't we use getDate(), getTime(), and all the other stuff like that.


05-08-2006, 03:47 PM
This code does break the day and the month will this work?

theDate= new Date();
months = new Array();
days = new Array();
months[1] ="jan.gif";
months[2] ="feb.gif";
months[3] ="mar.gif";
months[4] ="apr.gif";
months[5] ="may.gif";
months[6] ="jun.gif";
months[7] ="jul.gif";
months[8] ="aug.gif";
months[9] ="sep.gif";
months[10] ="oct.gif";
months[11] ="nov.gif";
months[12] ="dec.gif";
days[1] ="1st.gif";
days[2] ="2nd.gif";
days[3] ="3rd.gif";
days[4] ="4th.gif";
days[5] ="5th.gif";
days[6] ="6th.gif";
days[7] ="7th.gif";
days[8] ="8th.gif";
days[9] ="9th.gif";
days[10] ="10th.gif";
days[11] ="11th.gif";
days[12] ="12th.gif";
days[13] ="13th.gif";
days[14] ="14th.gif";
days[15] ="15th.gif";
days[16] ="16th.gif";
days[17] ="17th.gif";
days[18] ="18th.gif";
days[19] ="18th.gif";
days[20] ="20th.gif";
days[21] ="21st.gif";
days[22] ="22nd.gif";
days[23] ="23rd.gif";
days[24] ="24th.gif";
days[25] ="25th.gif";
days[26] ="26th.gif";
days[27] ="27th.gif";
days[28] ="28th.gif";
days[29] ="29th.gif";
days[30] ="30th.gif";
days[31] ="31st.gif";
function printDate() {
document.write('<img src="' + months[theDate.getMonth()+1] + '">'); // month
document.write('<img src="' + days[theDate.getDate()] + '">'); // day
// End -->



05-09-2006, 01:33 AM
its decent but it depends on what your trying to do if your trying to change pictures by the day then you don't need the month code, because this code displays two images - one depending on the month and one dpeneing on the day. but if you wanted it to display the images by date then just remove the month crap and put in your image urls for the days and just repeat them (because i'm sure you don't have 31 different pictures to display, but who knows). The only thing is that like i said before on the 31st it'll display one image and then 1st of the next month instead of going tothe next image it will just reset itself.