Place holder image with JS
2 posters
Page 1 of 1
Place holder image with JS
Hello,
I wanted to have a place holder image for the RPG image, since this field is empty is nothing is put in and I find it prettier if there is an image there.
I looked around and figured this could be accomplished with the usage of a JS script. I am, however, very inexperienced with these codes and tried something but it didn't work. Sadly.
So this is the script I tried, I put it in the template of the profile (templates > profile > profile_view_body)
Thanks in advance ^^
Greetings,
Hert
I wanted to have a place holder image for the RPG image, since this field is empty is nothing is put in and I find it prettier if there is an image there.
I looked around and figured this could be accomplished with the usage of a JS script. I am, however, very inexperienced with these codes and tried something but it didn't work. Sadly.
So this is the script I tried, I put it in the template of the profile (templates > profile > profile_view_body)
- Code:
<script type="text/javascript">
//<![CDATA[
if(typeof(_userdata) == "undefined")
var _userdata = new Object();
_userdata["image"] = "<img src="http://placehold.it/462x65" />";
//]]>
</script>
- Code:
<td width="462px"><div id="image">{RPG_IMAGE}</div></td>
Thanks in advance ^^
Greetings,
Hert
Re: Place holder image with JS
Hi @hert,
You want something like this, right ?
It'll get the element, and then check if the innerHTML content is empty. If it is, then it'll set the innerHTML for it.
The exclamation mark ( ! ) inverts the condition. In this one it means literally : "if img.innerHTML is empty" The equivalent would be :
You want something like this, right ?
- Code:
(function() {
var img = document.getElementById('image');
if (!img.innerHTML) img.innerHTML = '<img src="" alt="" />';
})();
It'll get the element, and then check if the innerHTML content is empty. If it is, then it'll set the innerHTML for it.
The exclamation mark ( ! ) inverts the condition. In this one it means literally : "if img.innerHTML is empty" The equivalent would be :
- Code:
if (img.innerHTML == '')
Similar topics
» [VERY super easy]Just need someone to place an image on this button. :3
» Can og:image metatag be edited to use image from the 1st post instead of banner
» Problems with Host Image Image/Insert Image
» Image style HTML Stop working when Image auto-resize is Enabled.
» Issue with forum background image and custom image display
» Can og:image metatag be edited to use image from the 1st post instead of banner
» Problems with Host Image Image/Insert Image
» Image style HTML Stop working when Image auto-resize is Enabled.
» Issue with forum background image and custom image display
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum