Forum Moderators: coopster
<?php
if(! (trim($rs["pImage"])=="" ¦¦ is_null($rs["pImage"]) ¦¦ trim($rs["pImage"])=="prodimages/")){?>
<img class="prodimage" src="<?php print $rs["pImage"]?>" border="0" alt="<?php print str_replace('"',' ',$rs[getlangid("pName",1)]) ?>" onclick="MM_openBrWindow('<?php print $rs["pLargeImage"]?>','','resizable=yes,width=210,height=410')" /> <?php
}elseif(! (trim($rs["pLargeImage"])=="" ¦¦ is_null($rs["pLargeImage"]) ¦¦ trim($rs["pLargeImage"])=="prodimages/")) {?>
<img class="prodimage" src="<?php print $rs["pLargeImage"]?>" border="0" alt="<?php print str_replace('"',' ',$rs[getlangid("pName",1)])?>" /> <?php
}else
print " ";?>
This code shows as you expect in the page source after it has loaded, but when you click the image the Javascript is not executing?
Not too surprising, really, as the onClick event is not associated with the IMG tag, except spotty support in some MS browsers (4.x comes to mind).
That is to say that it MAY work in some circumstances, but it's not 'real'.
Try using an anchor tag around the images and including your Javascript call as:
<a href="javascript:void MM_openBrWindow('<?php echo $rs["pLargeImage"]?>','','resizable=yes,width=210,height=410')"> instead of using it as an IMG tag attribute.
To tidy up, you'll want to add a closing brace to your final
else condition, too. Lastly, note how I used 'echo' instead of 'print', because the PHP print function uses more server resources than echo does, and you want to keep your code as performance-conscious as you can before things get really crazy. ;)
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<a href="javascript:void MM_openBrWindow('<?php echo $rs["pLargeImage"]?>','','resizable=yes,width=210,height=410')"><img src="<?php print $rs["pImage"]?>" alt="<?php print str_replace('"',' ',$rs[getlangid("pName",1)]) ?>" border="0" class="prodimage" /></a>
How does print use more than echo?
The PHP
print() 'function' (<- that classification being the key) prepares the presentation for the 'drawing' procedure utilizing the video subsystem and its generalized rendering instructions. The PHP
echo 'instruction' (<- note the single-quote pseudo-class delimiters) tells the shell to send output to 'stdout', which, in the case of the preparation via PHP of a web page for distribution to a web browsing client, results in the direct in-out data flow that delivers a nearly bit-for-bit representation of the intended result. To sum up;
print() is a little more resource-intensive but is still useful while echo is faster and is more useful in more situations. Second answer attempt ... (likewise) ...
Sounds like a Javascript function issue to me. Maybe the data isn't being passed properly, or interpreted properly, or something. Are you getting any kind of error message? What browser are you using for these tests?
<edit>That looks fine. Don't forget to make your tag code as 'accessible' as possible.
See the JS
void? That tells the interpreter to NOT send anything to the browser's display interpreter. Kinda like the PHP echo instruction; do the thing but, in this case, DON'T inform the video ... let the new window instance do that ... no need for two requests. Performance. ;)</edit> <edit2>Hmmm... adding the 'language' attribute made it work? Really? Wow. Sounds like a browser bug, or are you using Netscape 4.x? (hehe, just kidding :) Anyway, nice to hear a successful result. Happy motoring!</edit2>