Place holder image with JS

Go down

In progress Place holder image with JS

Post by Hert on September 8th 2015, 1:46 pm


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)
<script type="text/javascript">

                if(typeof(_userdata) == "undefined")
               var _userdata = new Object();
                _userdata["image"] = "<img src="" />";
This is the HTML that is relevant:
<td width="462px"><div id="image">{RPG_IMAGE}</div></td>
And here is an URL: and for an account that does have input in this field.

Thanks in advance ^^


Posts : 81
Reputation : 3
Language : Dutch and English

Back to top Go down

In progress Re: Place holder image with JS

Post by Ange Tuteur on September 8th 2015, 3:57 pm

Hi @hert,

You want something like this, right ?
(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 :
if (img.innerHTML == '')
Ange Tuteur

Male Posts : 13202
Reputation : 2917
Language : EN10, FR5, JA5
Location : Macungie, PA

Back to top Go down

Back to top

Permissions in this forum:
You cannot reply to topics in this forum