newbie question about displaying pictures in an array

P

Prophet

2 questions..........

I currently have a picture which changes depending on which day of the week
it is.

1) What I want to do is have the pictures sized for the page. As I also use
the pictures elsewhere, I currently make a second copy of the picture so
that it is the correct size - can I use the following code and size the
picture????

2) I wish to have more than 7 days worth of different pictures - I was going
to use random, but I want all users to see the same picture on the same day.
If I have 15 pictures, how do I do it???

Thank you in advance......



<script language="JavaScript">
<!--
function picture() {

var mydate=new Date()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym

var win2array=new Array("images/notifier.gif",
"images/key.gif",
"education/images/bl12.gif",
"images/notifier_right_1.gif",
"images/book.gif",
"images/mwglbcy_seal.jpe",
"education/images/b333.gif")

document.write("<p align='right'><img src = '" + win2array[day] + "'/>")}
// -->
</script>
 
P

Peter Schaefer

If you can figure out what I'm doing, this may help...
(writing it quick from work. I'm using your variables.)

var monthlengths=(31,28,31,30,31,30,31,31,30,31,30,31);
var dayofyear=0;
for(x=0x<month;x++)
{
dayofyear+=monthlengths[x];//get all days of prev months
}
dayofyear+=daym; //add this months day
var daymod=dayofyear%win2array.length;//modulo remainder value to use

document.write("<p align='right'><img src = '" + win2array[daymod] +
"'/>")}

this will work with any number of images

hope it helps

TheGeek
 
R

RobG

Prophet said:
2 questions..........

I currently have a picture which changes depending on which day of the week
it is.

1) What I want to do is have the pictures sized for the page. As I also use
the pictures elsewhere, I currently make a second copy of the picture so
that it is the correct size - can I use the following code and size the
picture????

You can set whatever height/width you like and the browser will
stretch/shrink the image to fit. But the result may look pretty awful
depending on the resampling algorithim used by the browser.
2) I wish to have more than 7 days worth of different pictures - I was going
to use random, but I want all users to see the same picture on the same day.
If I have 15 pictures, how do I do it???

Have a server-side program copy the 'pictures of the day' to the
appropriate URLs on your server. Zero client-side scripting and
everyone gets the same image set for whatever your update interval is
regardless of client local time settings, daylight saving, internal
clock errors, javascript non-availability, etc.

That is unless the images are somehow relevant to the local time of the
client.

[...]
document.write("<p align='right'><img src = '" + win2array[day] + "'/>")}

And if client scripting is not available?

[...]
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Wed, 3 Aug 2005 14:41:36, seen in
Peter Schaefer said:
If you can figure out what I'm doing, this may help...
(writing it quick from work. I'm using your variables.)

var monthlengths=(31,28,31,30,31,30,31,31,30,31,30,31);
var dayofyear=0;
for(x=0x<month;x++)
{
dayofyear+=monthlengths[x];//get all days of prev months
}
dayofyear+=daym; //add this months day
var daymod=dayofyear%win2array.length;//modulo remainder value to use

document.write("<p align='right'><img src = '" + win2array[daymod] +
"'/>")}

this will work with any number of images

Sort of; in leap years, the picture of Feb 29 may be repeated on Mar 1,
and the cycle will probably break at year-end.

To get a change every 24 hours, it is only necessary to use
DayCount = new Date()/864e5 ; PicNo = DayCount % Len

If the change must be at user's midnight, consider

D = new Date()
Off = D.getTimezoneOffset()
DayCount = (D - Off*6000)/864e5 // or use two minuses or pluses
...

Untested, but something like that should work. Read the newsgroup FAQ
:-
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Thu, 4
Aug 2005 04:42:59, seen in RobG
Prophet wrote:

Have a server-side program copy the 'pictures of the day' to the

Server-side programming is not always available.
appropriate URLs on your server. Zero client-side scripting and
everyone gets the same image set for whatever your update interval is
regardless of client local time settings, daylight saving, internal
clock errors, javascript non-availability, etc.
That is unless the images are somehow relevant to the local time of the
client.

He did day day-of-the-week, which is likely to mean user local time not
GMT.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top