Web Analytics Made Easy -
StatCounter undefined parameter for Image, only half the time? - CodingForum

Announcement

Collapse
No announcement yet.

undefined parameter for Image, only half the time?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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>

    Comment


    • #3
      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...

      Comment

      Working...
      X