If statement in MM_openBrWindow doesn't run
Posted: Mon Sep 10, 2012 3:21 pm
Hello Everyone,
I have a javascript function in my library that allows another larger window to be opened when a user clicks on a thumbnail image. The function is as follows:
The javascript that calls the function has an if statement within it that displays a thumbnail (if it exists) or a generic No Photo image if the user did not upload an image. The code for this is as follows:
If there is a thumbnail, it will be displayed and when a user clicks on the image (which is also a link) a new window opens displaying the full size image. This works well except that when the user has not uploaded an image (and therefore the No Photo image is displayed) if they click on that image, a new window opens and the user is greeted with an Object Not Found error message. I don't think may users would click on the No Photo image, but I would like their experience to be a bit better. I have attempted several versions of the following code and can't get any of them to work. The code is:
Here I'm trying to use two if statements, one to display the thumbnail or No Photo image and another to either open a new window and display the full size image or in the case that the user has not uploaded a photo, a Null Link (which should not allow the user to follow the link). There is no reason a user should be able to follow a link to nowhere.
What happens is that when I place the cursor over the thumbnail or the No Photo image, I can see the ...uploads/'.$row_products['product_id'].'a.jpg in the component bar (which is normal), but clicking on either type of thumbnail (real or No Photo), does not open another window. Instead, the user lands on a page displaying an Object Not Found error message in the existing window. The address bar then displays something such as http://www.siteName/uploads/'.$row_products['product_id'].'a.jpg - not the resolved address. It is as if the dynamic product_id is not passed along.
This confuses me, I don't know why the product_id would not be passed, or is the problem something else entirely? Is the function unable to handle the if statement in the call to MM_openBrWindow? If someone could give me an idea of what the problem is, I'd really appreciate it!
Cheers,
Rick
I have a javascript function in my library that allows another larger window to be opened when a user clicks on a thumbnail image. The function is as follows:
Code: Select all
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}Code: Select all
<TD>
<a href="'uploads/'.$row_products['product_id'].'a.jpg'" onClick="MM_openBrWindow('<?php echo
'uploads/'.$row_products['product_id'].'a.jpg' ?>','','width=600,height=450'); return false"> <?php
if (file_exists('uploads/'.$row_products['product_id'].'a.jpg')) { ?>
<img src="<?php echo 'uploads/'.$row_products['product_id'].'a.jpg'; ?>" width="132" height="99" border="0"><?php ;
} else { ?>
<img src="<?php echo 'images/no_photo.gif'; ?>" width="132" height="99" border="0"><?php ;
} ?>
</TD>Code: Select all
<TD>
<a href="'uploads/'.$row_products['product_id'].'a.jpg'" onClick= <?php
if (file_exists('uploads/'.$row_products['product_id'].'a.jpg')) {
?> "MM_openBrWindow('<?php echo 'uploads/'.$row_products['product_id'].'a.jpg'; ?>', '', width=600,height=450'); return false"> <?php ;
} else {
?> <a href="javascript:void(0);"> <?PHP // WANT TO HAVE "NO LINK" WHEN THERE IS NO PHOTO FOR THE ITEM
}
if (file_exists('uploads/'.$row_products['product_id'].'a.jpg')) {
?><img src="<?php echo 'uploads/'.$row_products['product_id'].'a.jpg'; ?>" width="132" height="99" border="0"><?php ;
} else {
?><img src="<?php echo 'images/no_photo.gif'; ?>" width="132" height="99" border="0"><?php ;
} ?>
</a>
</TD>What happens is that when I place the cursor over the thumbnail or the No Photo image, I can see the ...uploads/'.$row_products['product_id'].'a.jpg in the component bar (which is normal), but clicking on either type of thumbnail (real or No Photo), does not open another window. Instead, the user lands on a page displaying an Object Not Found error message in the existing window. The address bar then displays something such as http://www.siteName/uploads/'.$row_products['product_id'].'a.jpg - not the resolved address. It is as if the dynamic product_id is not passed along.
This confuses me, I don't know why the product_id would not be passed, or is the problem something else entirely? Is the function unable to handle the if statement in the call to MM_openBrWindow? If someone could give me an idea of what the problem is, I'd really appreciate it!
Cheers,
Rick