Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-18-2002, 04:48 PM   PM User | #1
pascal_scf
New to the CF scene

 
Join Date: Jun 2002
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
pascal_scf is an unknown quantity at this point
Question undefined parameter for Image, only half the time?

I have a VERY weird problem.
I pass the image name to a function which uses its 'name', 'src', 'alt', 'width' and 'height' properties. The thing is, for half the pictures (always the sames, and I have found no pattern whatsoever), the properties return 'undefined', for the other half, they are working good.
I work with ColdFusion and this code is part of a loop, and so every image has the exact same HTML code after the query has been parsed, except for the image name/alt/src.

Here's a quite simple part of my code, I have an image with a link and a javascript popup window to display the picture full-size :

<a href="javascriptopPhoto(photo_species_603)">
<img name="photo_species_603" src="http://www.speciesatrisk.gc.ca/Species/Images/Photos/spp603p1.jpg" alt="Northern Abalone" align="right" width="200" vspace="5" hspace="5" border="1">
</a><br>

I pass the name of the image as parameter in the function.
Here is the function :

<script language="Javascript">
function popPhoto(nom_photo) {
fen=window.open("","fen_visu","directories=no, width=500, height=500, location=no, menubar=no, personalbar=no, resizable=no, scrollbars=yes, toolbar=no");
fen.document.writeln('<div align="center">');
fen.document.writeln(nom_photo.name+'<br>'+nom_photo.alt+'<br><img src="'+nom_photo.src+'" name="la_photo">');
fen.document.writeln('<br>Width:'+fen.document.la_photo.width+'&nbsp;&nbsp;Height:'+fen.document.la_ photo.height+'<br>');
fen.document.writeln('<p align="right"style="font-family: Arial, Helvetica, Sans-Serif; font-size: 12pt; padding-right: 10px;"><a href="javascript:window.close()">Close</a></p>');
fen.document.writeln('</div>');
fen.document.close();
fen.focus();
}
</script>


Has anyone ever run into this? I am seriously lost as it works on some... The only thing I could think was that maybe, somehow, the parameter passed (the image-object name) is invalid...

Thanks,

Pascal
pascal_scf is offline   Reply With Quote
Old 06-18-2002, 08:45 PM   PM User | #2
JohnKrutsch
Regular Coder

 
Join Date: Jun 2002
Location: The Planet Earth Code Poet: True
Posts: 282
Thanks: 0
Thanked 1 Time in 1 Post
JohnKrutsch is an unknown quantity at this point
I think it is just a problem with how you are refering to the image attributes. Try this:


<a href="javascript: popPhoto('photo_species_603')">
<img name="photo_species_603" src="http://www.speciesatrisk.gc.ca/Species/Images/Photos/spp603p1.jpg" alt="Northern Abalone" align="right" width="200" vspace="5" hspace="5" border="1">
</a><br>

<script language="Javascript">
function popPhoto(nom_photo) {
fen=window.open("","fen_visu","directories=no, width=500, height=500, location=no, menubar=no, personalbar=no, resizable=no, scrollbars=yes, toolbar=no");
fen.document.writeln('<div align="center">');
fen.document.writeln(document.images[nom_photo].name+'<br>'+document.images[nom_photo].alt+'<br><img src="'+document.images[nom_photo].src+'" name="la_photo">');
fen.document.writeln('<br>Width:'+fen.document.la_photo.width+' Height:'+fen.document.la_photo.height+'<br>');
fen.document.writeln('<p align="right"style="font-family: Arial, Helvetica, Sans-Serif; font-size: 12pt; padding-right: 10px;"><a href="javascript:window.close()">Close</a></p>');
fen.document.writeln('</div>');
fen.document.close();
fen.focus();
}
</script>
JohnKrutsch is offline   Reply With Quote
Old 06-18-2002, 08:58 PM   PM User | #3
pascal_scf
New to the CF scene

 
Join Date: Jun 2002
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
pascal_scf is an unknown quantity at this point
Cool

Thank you.

Actually, I believe I may have found the answer.

I have added this little script just before the image to try to go around the problem:

<script language="JavaScript">
js_photo_species_603 = new Image();
js_photo_species_603.src = 'http://www.the-url.com/image.jpg';
</script>

and I pass the js_photo_species_603 instead of the photo_species_603.

It works well, and I think it was that more than one images on my page had the same 'name', as it is a query-generated page with repeating species name... So probably when the image appeared more than once it was screwed...
pascal_scf is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:27 AM.


Advertisement
Log in to turn off these ads.