Click to See Complete Forum and Search --> : Question about displaying images


brettstix
09-18-2009, 12:12 AM
I have a lot of images displayed on my web page using HTML like this...

<img src="www.mypics.com/pic1.jpg">

As I am regularly changing the pictures I was hoping to be able to store the url for each pictre in a variable so I can have them all in one place e.g.

<HTML>
<TITLE>
My Page
</TITLE>
<HEAD>
Define variable IMAGE1 = "www.mypics.com/pic1.jpg" <!-- I want to store the url in a variable -->
Define variable IMAGE2 = "www.mypics.com/pic2.jpg" <!-- So it is easier to change them -->
</HEAD>
<BODY>
...
...
...
<IMG src=IMAGE1>
...
...
...
<IMG src=IMAGE2>
...
...
...
</BODY>
</HTML>

This way if I want to change the url for each image I don't have to search through the document and can change them all easily.

Is this possible using HTML? Is this possible using Javascript?

If so, could someone point me in the right direction?

Any help would be greatly appreciated.

Thanks.

Charles
09-18-2009, 04:49 AM
It's possible but yucky to do that with JavaScript. Huge numbers of good people do not use JavaScript. Unless your images are meaningless and you wouldn't mind their absence do this server side. Do you have access to PHP?

brettstix
09-18-2009, 06:23 AM
Unfortunately I don't have access to php on this server. I've used it before and I know it would work quite well.

Thanks anyway. I will have to keep doing what I've been doing in the past.

brettstix
09-18-2009, 05:53 PM
I am not sure if this is poor coding or not but it works.


<html>
<head>
</head>
<body>
<script type="text/javascript">
var FirstPictureURL = "http://media.images.com/graphics/logo.png";
var SecondPictureURL = "http://www.retroragamuffins.com.au/includes/templates/nifty_zen/images/logo.gif";
</script>
Some code here<p>
<script type="text/javascript">
document.write("<img src=\"" + FirstPictureURL + "\">");
</script>
<p>Some more code here<p>
<a href="http://www.retroragamuffins.com.au">
<script type="text/javascript">
document.write("<img src=\"" + SecondPictureURL + "\">");
</script>
</a>
<p>The rest of the code
</body>
</html>