The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Place holder image with JS

View previous topic View next topic Go down

In progress Place holder image with JS

Post by Hert on Tue 8 Sep 2015 - 7:46

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)
Code:
<script type="text/javascript">
//<![CDATA[

                if(typeof(_userdata) == "undefined")
               var _userdata = new Object();
                _userdata["image"] = "<img src="http://placehold.it/462x65" />";
           
//]]>
</script>
This is the HTML that is relevant:
Code:
<td width="462px"><div id="image">{RPG_IMAGE}</div></td>
And here is an URL: http://dungeon-explorers.actieforum.com/u3 and http://dungeon-explorers.actieforum.com/u1 for an account that does have input in this field.

Thanks in advance ^^

Greetings,
Hert
avatar
Hert
Forumember

Posts : 81
Reputation : 3
Language : Dutch and English

http://afterthefall.actieforum.com/

Back to top Go down

In progress Re: Place holder image with JS

Post by Ange Tuteur on Tue 8 Sep 2015 - 9:57

Hi @hert,

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 == '')
avatar
Ange Tuteur
Forumaster

Male Posts : 13085
Reputation : 2759
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


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