Jump to content

How can I display a default image when no image exists?


Recommended Posts

On your details page there is an option to show a default image if you display your file as image. But if you do not have a file field to display your image and you only have the link to the image then you need to have an extra line of the code to check and see if the URL is blank then use a default URL. I have sample of the code, you are welcome to borrow it:
 

<script>
var image = '[@field:file1]';
if (image != "") {
document.write("[@field:file1]'>");
}
</script>

Make sure to replace file1 with your file field ID and also replace DefaultImageURL with URL of the image you would like to have as default.

Link to comment
Share on other sites

Well you can try this:

 

<script type="text/javascript">
var image= '[@field:file1]';

if (image != "") {

document.write("file1]','popup','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=750,height=600'))\">");

}

else

{

document.write("URL','popup','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=750,height=600'))\">DefaultImageURL\" alt=\"Default\" />");

}

</script>

URL is the URL of the large image in here.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...