...

View Full Version : define a path for an image source string



bdjdawg
06-24-2008, 07:53 PM
I want to show multiple images with the same filename except for the numbers on the end. I am trying to define a path for an image source through javascript. Any help would be appreciated. Thanks!

image filename sample: "http://www.website.com/Azul1.jpg"

<html>
<head>

<script language="Javascript">
var mypage = "http://www.website.com/Azul"
document.write(mypage)
</script>

</head>

<center>

<img src="\'+mypage+\'1.jpg" height="50%">
<img src="\'+mypage+\'2.jpg" height="50%">
<img src="\'+mypage+\'3.jpg" height="50%">

</body>
</center>
</html>

Mad Mouser
06-24-2008, 08:27 PM
Try setting a loop up.

If you have 10 pictures, and the first picture is numbered "1":



var mypage = "http://www.website.com/Azul";

for (i=1; i < 11; i++) {

document.write(mypage + i);

}

bdjdawg
06-24-2008, 09:16 PM
Cool. Now how does that fit into the <img src...>?

Basscyst
06-24-2008, 10:33 PM
While doing this does make it easier to code the page, it will not display the images to any user with javascript enabled, here is the code regardless:



window.onload=function(){
for(var i=0;i<10;i++){
var img=document.createElement('img');
img.setAttribute('src','images/myimage'+i+'.jpg');
document.body.appendChild(img);
}
}


Basscyst



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum