Hi all… I’m here as many users to learn and share (more learn as you will see :rolleyes: )
This time I’m trying to use a random image script that looks like this between <head> – </head>
[quote]
<!– Start random images –>
<script language=”JavaScript”>
// Cargando las imagenes que se necesiten.
var foto = new Array() // no cambiar esto
foto[0] = ‘spidera-aa.jpg’
foto[1] = ‘spidera-ab.jpg’
foto[2] = ‘spidera-ac.jpg’
foto[3] = ‘spidera-ad.jpg’
foto[4] = ‘spidera-ae.jpg’
var j = 0
var p = foto.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = foto[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function muestrafoto(){
document.write(‘<img src=”‘+foto[whichImage]+'”>’);
}
//–>
</script>
<!– Ends random javascript –>
And this on the table
[quote]
<td><script language=”JavaScript”>
showImage();
</script> a</td>
It works just fine but in order of using random images in more than one cell in my page I copied the entire script between head to head and replace the “theimages”, “showimages”, and images name which works fine, but the entire page will have 4 to 6 spots with random images which will be an endless piece of code
My question is how can I modify or what should I modify in order to call the same random code with several spots… I did this but is not working…
[quote]
<!– Start random images javascript –>
<script language=”JavaScript”>
// Loading images.
var theImages = new Array() // stay fixed
var foto = new Array() // stay fixed
theImages[0] = ‘spider-01.jpg’
theImages[1] = ‘spider-02.jpg’
theImages[2] = ‘spider-03.jpg’
theImages[3] = ‘spider-04.jpg’
theImages[4] = ‘spider-05.jpg’
foto[0] = ‘spidera-aa.jpg’
foto[1] = ‘spidera-ab.jpg’
foto[2] = ‘spidera-ac.jpg’
foto[3] = ‘spidera-ad.jpg’
foto[4] = ‘spidera-ae.jpg’
var j = 0
var p = theImages.length;
var q = foto.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
for (i = 0; i < q; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
preBuffer[i].src = foto[i]
}
var whichImage = Math.round(Math.random()*(p-1));
var whichImage = Math.round(Math.random()
function showImage(){
document.write(‘<img src=”‘+theImages[whichImage]+'”>’);
document.write(‘<img src=”‘+foto[whichImage]+'”>’);
}
//–>
</script>
<!– Finish random images javascript –>
What should I change in order of adding more than one random in the same page using the same code?
Yes I’m new on javascript 😮 but I’m trying…. I’m trying… 😮
Any help is well appreciated