Forum Moderators: mack
I've this javascript that show random images. I use because i like it to be more organized. I used this script on my table. eg.
<script type="text/javascript" src="../scripts/java.js"></script>
the problem is i dont want my images to go random. i know that the images goes random is becasue i have the math.floor. etc..
Please can someone get rid of the images to go randomly..
thanks
here is the script:
var img_width = "150";
var img_height = "175";
var img_title = "Great Deals";var ad=new Array()
//insert here your images src
ad[0]='http://example.com/0013.jpg';
ad[1]='http://example.com/2ecgc9g.jpg';
ad[2]='http://example.com/igcaqw.jpg';
ad[3]='http://example.com/0001.jpg';
var links=new Array()
//insert here your links
links[0]='http://example.com/ngcle4';
links[1]='http://example.com/yhwwm9y';
links[2]='http://example.com/yjxhgp4';
links[3]='http://example.com/yhfamgy';
[b]var xy=Math.floor(Math.random()*ad.length);[/b]
document.write('<a href="'+links[xy]+'" target="_blank"><img src="'+ad[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'" border="0"></a>');
// End -->
[edited by: mack at 9:13 am (utc) on Jan. 25, 2010]
[edit reason] example.com used for links. [/edit]
//var xy=Math.floor(Math.random()*ad.length);
//document.write('<a href="'+links[xy]+'" target="_blank"><img src="'+ad[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'" border="0"></a>');
for (i=0;i<ad.length;i++) {
document.write('<a href="'+links[i]+
'" target="_blank"><img src="'+ad[i]+
'" width="'+img_width+'" height="'+img_height+
'" alt="'+img_title+'" border="0"></a>');
}
sorry..didn't realize i put the links there..i cant edit it back..bummer..
anyway thanks for the reply..but i dont know where to put that script you just gave me..
did u mean that i have to delete the:
var xy=Math.floor(Math.random()*ad.length);
document.write('<a href="'+links[xy]+'" target="_blank"><img src="'+ad[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'" border="0"></a>');
// End -->
and change it to your new script:
for (i=0;i<ad.length;i++) {
document.write('<a href="'+links[i]+
'" target="_blank"><img src="'+ad[i]+
'" width="'+img_width+'" height="'+img_height+
'" alt="'+img_title+'" border="0"></a>');
}
is this correct?
// this is a comment
will be ignored. It's a great way to experiment with other options and if it doesn't work, you can remove the comment lines and you're back where you were.
So the entire chunk of code I pasted can REPLACE the corresponding existing lines in the code. It all goes in the bottom of the code chunk, before your "// --> End" comment.
The logic is, instead of using random to set the image and link, it iterates through the list of images, hence the "i" variable.
Put it in a test page, try it out. :-)