Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-04-2006, 09:56 PM   PM User | #1
kimstanely
New Coder

 
Join Date: Apr 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
kimstanely is an unknown quantity at this point
Need help with timer

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.

PHP Code:


<html>

<
body>

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

var images.length;
var 
buff = new Array()
for (
0ki++){
   
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>


 <script type="text/javascript" language="javascript">
      imagesAppear();
    </script>

</body>
</html> 
kimstanely is offline   Reply With Quote
Old 05-06-2006, 12:05 PM   PM User | #2
boxxer03
Regular Coder

 
Join Date: Sep 2005
Location: Chicago, IL
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
boxxer03 is an unknown quantity at this point
Code:
<html>

<head>
<title>Image Swap</title>
<script type="text/javascript">
<!--
var images=new Array()
images[0]='glass.jpg'
images[1]='ball.jpg'
images[2]='123.jpg'

var current_image=0;

function imageSwap(){
document.picture.src=images[current_image]
document.picture.alt=images[current_image]
current_image=current_image+1

resetSwap=(current_image==images.length)?current_image=0:"";
setTimeout("imageSwap()",2000);
}
//-->
</script>
</head>

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

</html>
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.
__________________
I'm only telling you how I would do it, not how its supposed to be done. ;)
boxxer03 is offline   Reply With Quote
Old 05-06-2006, 12:07 PM   PM User | #3
boxxer03
Regular Coder

 
Join Date: Sep 2005
Location: Chicago, IL
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
boxxer03 is an unknown quantity at this point
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.
__________________
I'm only telling you how I would do it, not how its supposed to be done. ;)
boxxer03 is offline   Reply With Quote
Old 05-07-2006, 02:53 AM   PM User | #4
kimstanely
New Coder

 
Join Date: Apr 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
kimstanely is an unknown quantity at this point
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,
Kim
kimstanely is offline   Reply With Quote
Old 05-07-2006, 03:16 AM   PM User | #5
Jordans
New to the CF scene

 
Join Date: Apr 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Jordans is an unknown quantity at this point
I think some one should close this, besides you could always thank the people that helped you.
Jordans is offline   Reply With Quote
Old 05-07-2006, 09:13 AM   PM User | #6
boxxer03
Regular Coder

 
Join Date: Sep 2005
Location: Chicago, IL
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
boxxer03 is an unknown quantity at this point
I already replied to that thread.
__________________
I'm only telling you how I would do it, not how its supposed to be done. ;)
boxxer03 is offline   Reply With Quote
Old 05-08-2006, 12:44 AM   PM User | #7
kimstanely
New Coder

 
Join Date: Apr 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
kimstanely is an unknown quantity at this point
Jordans:

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.

Quote:
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,
Kim

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.

Thanks
Kim
kimstanely is offline   Reply With Quote
Old 05-08-2006, 02:39 AM   PM User | #8
boxxer03
Regular Coder

 
Join Date: Sep 2005
Location: Chicago, IL
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
boxxer03 is an unknown quantity at this point
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.
__________________
I'm only telling you how I would do it, not how its supposed to be done. ;)
boxxer03 is offline   Reply With Quote
Old 05-08-2006, 02:41 PM   PM User | #9
kimstanely
New Coder

 
Join Date: Apr 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
kimstanely is an unknown quantity at this point
Hi,

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

Thanks
Kim
kimstanely is offline   Reply With Quote
Old 05-08-2006, 02:47 PM   PM User | #10
kimstanely
New Coder

 
Join Date: Apr 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
kimstanely is an unknown quantity at this point
This code does break the day and the month will this work?

Code:
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('<br>');
document.write('<img src="' + days[theDate.getDate()] + '">'); // day
}
//  End -->
</script>
</HEAD>


<BODY>


<script>
printDate();
</script>
kimstanely is offline   Reply With Quote
Old 05-09-2006, 12:33 AM   PM User | #11
boxxer03
Regular Coder

 
Join Date: Sep 2005
Location: Chicago, IL
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
boxxer03 is an unknown quantity at this point
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.
__________________
I'm only telling you how I would do it, not how its supposed to be done. ;)
boxxer03 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:42 AM.


Advertisement
Log in to turn off these ads.