Archive for myfreeforum.org Before posting please check the "stickies" in the support forums.
Please ask questions in real English and not "txt". You will get a better response.
Please do not ask support questions via PMs.
 


       myfreeforum.org Forum Index -> Web page/template Editing
connorconway

Javascript - cycling images with a random start

I basically want a random image to show up on my webpage and start scrolling through more images i've set to that list.

Here's what I have. It'll bring up an image and then change to an error image:

Code:
<html>
<head>
<script type="text/javascript" language="javascript">
<!-- Hide script from old browsers

adImages = new Array("http://i155.photobucket.com/albums/s298/Connorconway/Office_Season_6_Blu-Ray.jpg","http://i155.photobucket.com/albums/s298/Connorconway/Halloween_Blu_Ray.jpg")
imgCt = adImages.length
firstTime = true

function rotate() {
if (document.images) {
if (firstTime) {
thisAd = Math.floor((Math.random * imgCt))
firstTime = false
}
else {
thisAd++
if (thisAd == imgCt) {
thisAd = 0
}
}
document.myPicture.src=adImages [thisAd]
setTimeout("rotate()", 3 * 1000)
}
}

// End hiding script from old browsers </script>

</head>

<body onload="rotate()">

<img src="http://i155.photobucket.com/albums/s298/Connorconway/Office_Season_6_Blu-Ray.jpg" width="400" height="300" name="myPicture" alt="Ad Banner" />

</body>
</html>


Website: http://tvmaniax.myfastforum.org/index.html
myff admin

I can't see anything obvious wrong.

But scripts like that will need manual debugging. How are you debugging? Often just using the "alert" statement will do the trick.
Nick(NR)

remove: <!-- Hide script from old browsers
and: // End hiding script from old browsers

might be nothing but to me the comment tag isn't closed ( -->) until the </script> tag.

http://www.w3schools.com/tags/tag_comment.asp
connorconway

Nick(NR) wrote:
remove: <!-- Hide script from old browsers
and: // End hiding script from old browsers

might be nothing but to me the comment tag isn't closed ( -->) until the </script> tag.

http://www.w3schools.com/tags/tag_comment.asp


I tried this but it didn't make any difference. However, I found out that the problem was because my random number generator was generating a non-numeric value due to the lack of brackets:

Code:
function rotate() {
if (document.images) {
if (firstTime) {
thisAd = Math.floor(Math.random()*imgCt);
firstTime = false
}


fixed it;

Thank you both for the very quick replies and information:)

       myfreeforum.org Forum Index -> Web page/template Editing
Page 1 of 1
Create your own free forum | Buy a domain to use with your forum