Php <img src"">

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ghoz
Forum Commoner
Posts: 38
Joined: Thu Jul 12, 2012 2:32 am

Php <img src"">

Post 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!
User avatar
Tiancris
Forum Commoner
Posts: 39
Joined: Sun Jan 08, 2012 9:54 pm
Location: Mar del Plata, Argentina

Re: Php <img src"">

Post 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.
Ghoz
Forum Commoner
Posts: 38
Joined: Thu Jul 12, 2012 2:32 am

Re: Php <img src"">

Post 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;';
User avatar
Tiancris
Forum Commoner
Posts: 39
Joined: Sun Jan 08, 2012 9:54 pm
Location: Mar del Plata, Argentina

Re: Php <img src"">

Post by Tiancris »

I always write ";" at the end of each line :)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Php <img src"">

Post 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)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply