Closed Thread Icon

Topic awaiting preservation: changing image question! Pages that link to <a href="https://ozoneasylum.com/backlink?for=8682" title="Pages that link to Topic awaiting preservation: changing image question!" rel="nofollow" >Topic awaiting preservation: changing image question!\

 
Author Thread
Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 06-01-2003 05:10

Hi, guys! How are you?
It has been very warm winter days for a couple of days here in NZ.
Hope you are doing well, guys.

Well, Would you give me a couple of chips to change an image? I mean when I visit web site, often see the images changing repeatedly. For example a couple images change every couple of seconds then go back to first image then do the same thing.

I succeed one image to another in 4 seconds. But I want to make it happen permanently as long as user stay the same page.

Here is my code:

code:
<html>
<head>
<title>Image Instances Example</title>
<script type="text/javascript">
var imageOne = new Image();
imageOne.src ="1.gif"

function change()
{

document.images[0].src = "1.gif";
}

setTimeout("change()", 4000);

</script>
</head>

<body>
<image src = "2.gif" >
<a href="56.htm">Click here</a>
</body>
</html>



I guess I need a sort of endless loop to make this function happen all the time. But it didn't work.......Hmm.....Would you have any idea, please?

Hiroki Kozai

quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 06-01-2003 11:31

Sounds like they're using animated gif's, nothing to do with Javascript whatsoever. If you wanted to do it with settimeout, it shouldn't be hard though:

code:
<script type="text/javascript"> 
var imageOne = new Image();
imageOne.src ="1.gif"
function change() {
if(switch){
imageOne.src = "2.gif";
} else {
switch = false;
imageOne.src = "1.gif";
}
setTimeout("change()", 4000);
}
</script>
<img src="1.gif" name="imageOne" alt="imageOne" onLoad="change();">


What you're doing here is changing a boolean (true/false) variable each time you change the image. Then you can tell which image is currently set, and so which one to change it to. Then the function calls itself after 4s, using settimeout, and so this will go on forever.

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 06-02-2003 04:02

Hi, quisja. many thanks for your reply.
Well, I modified my code like you did.
But I am afraid it did not work.

my new code is below:

code:
<html>
<head>
<title>Image Instances Example</title>
<script type="text/javascript">
var imageOne = new Image();
imageOne.src ="1.gif";
function change( )
{
if(switch){
document.imageOne.src = "2.gif";
}
else {
switch = false;
document.imageOne.src = "1.gif";
}
setTimeout("change( )", 4000);
}
</script>
</head>

<body>
<img src="1.gif" name="imageOne" alt="imageOne" onLoad="change( )">
<a href="56.htm">Click here</a>
</body>
</html>



Somereason, error has been caused. It said that object expected. But I cannot figure out what it means.......
Do you see anything???? Many thanks.

Hiroki Kozai

quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 06-02-2003 10:10

Um, what line is the error on? either I've missed something out in dealing with the image (I don't think so..), or you shouldn't have spaces between your brackets in naming/calling functions:

code:
function change( )
//should be:
function change()

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 06-03-2003 00:43

Hi, thanks for your reply.
It still doesn't work.
I think I did like you said.
Please see below:

code:
<html>
<head>
<title>Image Instances Example</title>
<script type="text/javascript">
var imageOne = new Image();
imageOne.src ="1.gif";
function change()
{
if(switch){
imageOne.src = "2.gif";
}
else {
switch = false;
imageOne.src = "1.gif";
}
setTimeout("change()", 4000);
}
</script>
</head>

<body>
<img src="1.gif" name="imageOne" alt="imageOne" onLoad="change();">
<a href="56.htm">Click here</a>
</body>
</html>



There is no space between blancket. Hmm.....Is there any problems?

Hiroki Kozai

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 06-03-2003 00:45

Oh, error message said:

quote:
line 22, object expected



What does it mean? I don't see that point...I am afraid.

Hiroki Kozai

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 06-03-2003 01:18

You are mixing what imageOne is. What you want to do is create 2 JS image objects and then replace the src of document.images['imageOne'].src with one of those 2 new images (ignore what is already there that's kinda meaningless once you start changing stuff)

<script type="text/javascript">
var imgOne = new Image(); \
imgOne.src ="1.gif"; // NOT the same as imageOne in the img tag
var imgTwo = new Image();
imgTwo.src = "2.gif";

switch = true;
function change( ) {
document.images['imageOne'].src = (switch) ? imgTwo.src : imgOne.src;
switch = (switch) ? false : true; // does switch = !switch work here?
setTimeout('change()', 4000);
}




.:[ Never resist a perfect moment ]:.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-03-2003 02:52

"object expected" usually means that you typed something that wasn't a variable name, and wasn't a function, and basically the browser couldn't figure out what it was supposed to be. It's saying, it expected an object, but it found something that it doesn't understand.

So your best bet is to go to the line number (22 in this case) (count lines from the top of the HTML file or use your text editor's Go To command, usually in the Edit menu if anywhere), and see if there's a typo there, or a variable that you didn't declare.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 06-03-2003 08:10

he's actually missing a closing bracket so his header JS is not getting loaded.

Calling the change function in the onLoad event is the missing object. (There should actually be two errors)



.:[ Never resist a perfect moment ]:.

« BackwardsOnwards »

Show Forum Drop Down Menu