Page 1 of 1

Php <img src"">

Posted: Tue Nov 06, 2012 7:38 am
by Ghoz
Hi,

This code will call the js

Code: Select all

<script src="http://export.giveawayoftheday.com/index.js"></script>
This code will output the url of the image

Code: Select all

<script type="text/javascript">document.write(gaotdObj.screenshot)</script>
How to echo the url to display the image in <img src=""> ???
Thanks!

Re: Php <img src"">

Posted: Tue Nov 06, 2012 9:23 am
by Tiancris
This should do the trick:

Code: Select all

<img id="theImage" src="">

<script>
document.getElementById("theImage").src = gaotdObj.screenshot;
</script>
Probably you have to use this code within an event like window.onLoad, or <body onload="">, that depends of how your app works.

Re: Php <img src"">

Posted: Tue Nov 06, 2012 7:49 pm
by Ghoz
Thanks, it works!
Anyway both of these codes are working, but which one should I use??

Code: Select all

echo 'document.getElementById("theImage").src = gaotdObj.screenshot';

Code: Select all

echo 'document.getElementById("theImage").src = gaotdObj.screenshot;';

Re: Php <img src"">

Posted: Wed Nov 07, 2012 1:25 pm
by Tiancris
I always write ";" at the end of each line :)

Re: Php <img src"">

Posted: Fri Nov 09, 2012 12:12 am
by social_experiment
Ghoz wrote:but which one should I use??
you should go for the option with the semi-colon at the end. a semi-colon indicates the end of a statement in javascript (as in other programming languages)