Click to See Complete Forum and Search --> : Picture of the day, dot show up int the browser


mofm_
12-10-2003, 12:14 AM
Hi ...

I want to have diffrent picture every time i access the page.. Descriptions comes along, the real problem comes in the body -- GO to the body...

<script type="text/javascript">

/* I created an array, therefore if i want to have a specific picture a specific day, This script i made for to have "links of the day", but i hope it should work this way also with images instead */

var daylinks=new Array()

daylinks[1]="465498.jpg"
daylinks[2]="54654.jpg"
daylinks[3]="sdfl.jpg"
daylinks[4]="pokjpo.jpg"
daylinks[5]="dsrw3.jpg"
daylinks[6]="mäpo90.jpg"
daylinks[7]="pouäpoiuj.jpg"
daylinks[8]="k7yh98.jpg"
daylinks[9]="p9087.jpg"
daylinks[10]="p098.jpg"
daylinks[11]="mp987.jpg"
daylinks[12]="må098.jpg"
daylinks[13]="m098.jpg"
daylinks[14]="p98n7.jpg"
daylinks[15]="mp9087.jpg"
daylinks[16]="n987+80.jpg"
daylinks[17]="098m09.jpg"
daylinks[18]="76tb.jpg"
daylinks[19]="u7btb8.jpg"
daylinks[20]="o798y09hk87.jpg"
daylinks[21]="i76gbo87o.jpg"
daylinks[22]="987hp987.jpg"
daylinks[23]="987h9jk.jpg"
daylinks[24]="987hynp98y.jpg"
daylinks[25]="98ynhp0uhjio.jpg"
daylinks[26]="ijp09uå.jpg"
daylinks[27]="jpg0ikm0i.jpg"
daylinks[28]="09ujöp9uopiupoijk.jpg"
daylinks[29]="g65t87i7.jpg"
daylinks[30]="loiutrvd6.jpg"
daylinks[31]="87hoi8uyk09iuiuupiuu.jpg"


/* Here Is Randomizer */

var slump=Math.random()
slump=slump*31

/* Correcting overflow */
if (slump>31){
slump=31
}

slump=Math.round(slump)

</script>
<body>

<!-- Here when i want to put it in the src= i cant get it to work, nothing shows on the page when i view it int the browser -->

<IMG SRC="+daylinks[slump]+" ALT="Todays Picture" height="Auto" width="Auto">

<!-- note: I hope my discription is good and where the problem is, i am a Newbie -->

olaf
12-10-2003, 01:12 AM
while searching for javascript and random on google i found this page
on rank 3:
http://www.javascript-page.com/ranimage.html

little jim
12-10-2003, 01:27 AM
It's doing this because in your IMG SRC you are giving it the text string "+daylinks[slump]+". What you need to do is have your javascript say...

"document.write("<img src=\"" +daylinks[slump]+"\" alt=\"Todays Picture\">");

mofm_
12-10-2003, 02:38 AM
Thanks for the answer :)

But it still doesnt show the picture.:( The only diffrents is now i could see where the picture should have been shown and then it saids "undefined" ...

<img src=\"" +ranimage()+ "\" alt=\"" +ranimage()+ "\">

mofm_
12-10-2003, 03:06 AM
Wrong paste in iam trying diffrent approches, here comes the correct one..

SRC='\""daylinks[slump]+ "\" ALT=\"" Todays Picture "\"

Pittimann
12-10-2003, 03:33 AM
Hi!

I think, the easiest solution for you is, to give your image a name and set the src by the script, instead of document.write it.

Something like that should work for you:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function getPicture(){
var daylinks=new Array()
daylinks[1]="465498.jpg"
daylinks[2]="54654.jpg"
daylinks[3]="sdfl.jpg"
daylinks[4]="pokjpo.jpg"
daylinks[5]="dsrw3.jpg"
daylinks[6]="mäpo90.jpg"
daylinks[7]="pouäpoiuj.jpg"
daylinks[8]="k7yh98.jpg"
daylinks[9]="p9087.jpg"
daylinks[10]="p098.jpg"
daylinks[11]="mp987.jpg"
daylinks[12]="må098.jpg"
daylinks[13]="m098.jpg"
daylinks[14]="p98n7.jpg"
daylinks[15]="mp9087.jpg"
daylinks[16]="n987+80.jpg"
daylinks[17]="098m09.jpg"
daylinks[18]="76tb.jpg"
daylinks[19]="u7btb8.jpg"
daylinks[20]="o798y09hk87.jpg"
daylinks[21]="i76gbo87o.jpg"
daylinks[22]="987hp987.jpg"
daylinks[23]="987h9jk.jpg"
daylinks[24]="987hynp98y.jpg"
daylinks[25]="98ynhp0uhjio.jpg"
daylinks[26]="ijp09uå.jpg"
daylinks[27]="jpg0ikm0i.jpg"
daylinks[28]="09ujöp9uopiupoijk.jpg"
daylinks[29]="g65t87i7.jpg"
daylinks[30]="loiutrvd6.jpg"
daylinks[31]="87hoi8uyk09iuiuupiuu.jpg"
var slump=Math.random()
slump=slump*31
if (slump>31){
slump=31
}
slump=Math.round(slump)
document.POTD.src=daylinks[slump];
}
</script>
</head>
<body onload="getPicture()">
<IMG SRC="dummy.gif" NAME="POTD" ALT="Todays Picture">
</body>
</html>

Cheers - Pit

mofm_
12-10-2003, 04:10 AM
Thanks for that solution, it looks right - but it still show almost the same result - why it doesnt work for me!!
see the picture..

Pittimann
12-10-2003, 04:21 AM
Hi!

The .jpg files have to be in the same folder like the file with the script!

Sure, that helps...

Cheers - Pit

mofm_
12-10-2003, 04:36 AM
yes :) i have the images in the same Directory...

and if i right click and click Property i can se that i can see the path and a image file name ... im begining to think that this isnt my day..

Pittimann
12-10-2003, 04:50 AM
Hi!

The right click and property stuff only proves, that your browser attempted to load the image from the directory, where your file with the script is situated.

If your images were there, the randomly chosen one should be displayed...

Cheers - Pit

little jim
12-10-2003, 01:45 PM
It now seems that your script isn't the problem, it may be that...

[list=a]
There is something wrong with the Jpg's, try viewing them in an image editor
There is something weird about your browser.
The jpg's arn't where you say they are.
[/list=a]

try adding a test jpg which you know is valid, and then view that in the browser.

mofm_
12-11-2003, 03:27 PM
Im glad that U guys try to help me... Thanks...

okay i.c the property only shows that the path to the image and that is correct shown, good.. But the image is still not shown.. strange

a: the picture can be open in paint, n problem with it

b: i hav checket it in opera and in 2 other computer at work and same thing happend there

c: the pictures ar in tha same directory as the web page so it should work then

:confused:

So what is then wrong..

mofm_
12-11-2003, 06:00 PM
:D

Now I rewrote the whole code on new page and now its working :cool:

I cant see any diffrents between the codes, just happy its working :) greate

thanks guys