Skip to content Skip to sidebar Skip to footer

Variable For Img Src=

I have a question. Firstly, I am not going to pretend that I know what I am talking about here. I am a newbie to http and JavaScript. I think my question may be answered in this p

Solution 1:

Yes, that page probably does answer your question. Basically, you want this javascript:

<scripttype="text/javascript">document.getElementById('image').src = "yourpicture.png";
</script>

Except you want to replace the "yourpicture.png" with the function you wrote to generate the correct path to the image on disk, so...

<scripttype="text/javascript">document.getElementById('image').src = displaydate();
</script>

Of course, you might need to modify this a bit for your own uses, the getElementById will take as an argument whatever the id attribute of your < img > tag is. You probably want to execute the above javascript after your page has loaded, i.e.:

<html><head><scripttype="text/javascript">functionload()
{
document.getElementById('image').src = displaydate();
}

functiondisplaydate()
{
//your displaydate() function here
}
</script></head><bodyonload="load()"><imgsrc="nothing.jpg"id="image"name="image"/></body></html>

Solution 2:

You should just need to change this line

document.write("http://host1/Shared/" +year+ "/" +month+ "/" +day+ "/cpu_abs.gif");

to

return "http://host1/Shared/" +year+ "/" +month+ "/" +day+ "/cpu_abs.gif";

Post a Comment for "Variable For Img Src="