Click to See Complete Forum and Search --> : What's wrong with this script?


krismisz
02-21-2003, 08:21 PM
Hey everybody. I have a script that I've been working on that just doesn't work. I'm a beginner so it might be an easy fix and it might not.

On javascript.internet.com there are some scripts that give a "quote of the day", "random image", and "tip of the day". I took portions from each of these scripts in a vain effort to try to create a script that will show a selected image on a previously specified day.

However, I keep getting an "undefined" error, and even when I get no error, no image pops up. What's wrong with this script:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var theImages = new Array()
Stamp = new Date();
today = Stamp.getDate();
theImages[1] = '2.jpg';
theImages[2] = '3.jpg';
theImages[3] = '4.jpg';
theImages[4] = '5.jpg';
theImages[5] = '6.jpg';
theImages[6] = '7.jpg';
theImages[7] = '8.jpg';
theImages[8] = '9.jpg';
theImages[9] = '10.jpg';
theImages[10] = '11.jpg';
theImages[11] = '12.jpg';
theImages[12] = '13.jpg';
theImages[13] = '14.jpg';
theImages[14] = '15.jpg';
theImages[15] = '16.jpg';
theImages[16] = '17.jpg';
theImages[17] = '18.jpg';
theImages[18] = '19.jpg';
theImages[19] = '20.jpg';
theImages[20] = '1.jpg';
theImages[21] = '2.jpg';
theImages[22] = '3.jpg';
theImages[23] = '4.jpg';
theImages[24] = '5.jpg';
theImages[25] = '6.jpg';
theImages[26] = '7.jpg';
theImages[27] = '8.jpg';
theImages[28] = '9.jpg';
theImages[29] = '10.jpg';
theImages[30] = '11.jpg';
theImages[31] = '12.jpg';

var whichImage = ('<i>' + theImages[today] + '</i><br>');
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}
// End -->
</script>


<body>
<p>
<b>Picture of the Day:</b>

<script>
showImage();
</script>


I think the problem is in the "var whichImage = ...." part, but I don't know how to define "whichImage"! I'm very much a beginner and I would appreciate anyone's help that I can get on this!

Thanks in advance!
Krismisz

khalidali63
02-21-2003, 09:08 PM
Looks like you are trying to load an image for the day of the month..you need to do this

theImages[today.getDay()]

cheers

Khalid

krismisz
02-21-2003, 09:16 PM
Where does this go? theImages[today.getDay()]

Where do I put it?

Thanks for a fast reply!
krismisz

Skrlin Site
02-21-2003, 09:24 PM
I think what khalidali63 meant was to try this:


var whichImage = ('<i>' + theImages[today.getDay()] + '</i><br>');

khalidali63
02-21-2003, 09:26 PM
I had no idea you don't knoe the code you posted at all..


Skrlin Site has cleared it..lol
thanks

krismisz
02-21-2003, 09:33 PM
Sorry guys. I'm a true beginner at all of this so sorry about the confusion.

But when I put in the code that Skrlin Site gave, I got an "Undetermined String Constant" error and an "Object expected" error. What now?

krismisz

khalidali63
02-21-2003, 10:04 PM
Here you my friend..

Copy the code below in your html page in the same folder where you have all those numbered jpg images.

cheers

Khalid


<body>
<p>
<b>Picture of the Day:</b>
<script type="text/javascript">
var number = 2;
var limit = 32;
var range = 21;
var theImages = new Array();
Stamp = new Date();
today = parseInt(Stamp.getDate());
window.onload = createImageArray;
function createImageArray(){
for(n=1;n<limit;n++){
var img = new Image();
img.src = getGetNumber()+".gif";
theImages[n] = img;
}
showImage();
}
function showImage(){
var whichImage = theImages[today].src;
document.write('<img src="'+whichImage+'">');
}

function getGetNumber(){
if(number==range){
number = 1;
}
return number++;
}
</script>

</body>

krismisz
02-21-2003, 10:34 PM
Thanks so much, khalidali63 and Skrlin Site, both for helping and for being patient with this beginner.

Thanks so much!
krismisz