Closed Thread Icon

Preserved Topic: Preloading images Pages that link to <a href="https://ozoneasylum.com/backlink?for=18262" title="Pages that link to Preserved Topic: Preloading images" rel="nofollow" >Preserved Topic: Preloading images\

 
Author Thread
Lala
Bipolar (III) Inmate

From: Montreal, Canada
Insane since: Feb 2002

posted posted 05-27-2002 20:30


yes... me again :S
im trying to preload some images so they dont flash when the onclick event is called
preloadint the pic:
var p1=new Image();
p1.src='1.jpg';

the function:
function cambia(what)
{
if (what==1)
{
document.getElementById('pic').src ="'+p1+'";
}
}

the tag:
<td class="h" id="17"><img src="5p.jpg" onClick="cambia(5)"></td>

according to me it should work but it doesnt ... *whisper* im not surprise..

100 bugs
Lala


Lala
Bipolar (III) Inmate

From: Montreal, Canada
Insane since: Feb 2002

posted posted 05-27-2002 20:32

this is what i meant :s

document.getElementById('pic').src ="'+p1.src+'";

100 pics
Lala

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-27-2002 21:47

This is mostly a string problem.

Remember that double quotes and single quotes don't match each other. When you set the source to "'+p1.src+'", you're setting it to

'+p1.src+'

since there are no double quotes inside your double-quoted string. And since there are no images called '+p1.src+' anywhere, it can't load the image.

Here's what you want to do. You want the source to be p1.src, so merely set it like this:

document.getElementById('pic').src = p1.src;

It seems that what you're trying to do right now is set it to "" + p1.src + "", but adding those extra empty strings on either side is unecessary. Because they're empty.

Now, you also have to set id="pic" inside your image tag for that to reference the correct element. And also, your function tests if(what == 1), and you're calling it as cambia(5). You'll either need to change the 1 to a 5, or the 5 to a 1. If they don't match, the function won't do anything.

Lala
Bipolar (III) Inmate

From: Montreal, Canada
Insane since: Feb 2002

posted posted 05-27-2002 22:20

Thanks again slime

actually i have several images 1,2,3 and so on but i pasted the wrong tag :S (thats why u saw a function with a wrong parameter #)

Thanks, merci, gracias .

100 smiles.
Lala



« BackwardsOnwards »

Show Forum Drop Down Menu