/    Sign up×
Community /Pin to ProfileBookmark

Double Image Arrays

I need to put two image arrays in one code with one that selects randomly and one that cycles. The codes both work when they are seperate but when they are put together only the first one works, this is the code:

<HTML>
<HEAD>
<TITLE>HTML and JavaScript</TITLE>
<SCRIPT>
var imgArray = new Array(4);
imgArray[0] = new Image;
imgArray[0].src = “winter2.jpg”;
imgArray[1] = new Image;
imgArray[1].src = “spring2.jpg”;
imgArray[2] = new Image;
imgArray[2].src = “summer2.jpg”;
imgArray[3] = new Image;
imgArray[3].src = “fall2.jpg”;
var index = 0;

function select()
{
index = Math.floor(Math.random() * 4);
document.banner.src = imgArray[index].src;
setTimeout(“select()”,1000);
return;
}
</SCRIPT>
<SCRIPT>
var imgSlide = new Array(4);
imgArray[0] = new Image;
imgArray[0].src = “winter.jpg”;
imgArray[1] = new Image;
imgArray[1].src = “spring.jpg”;
imgArray[2] = new Image;
imgArray[2].src = “summer.jpg”;
imgArray[3] = new Image;
imgArray[3].src = “fall.jpg”;
var index = 0;

function cycle()
{
document.seasons.src = imgSlide[index].src;
index++;
if (index == 4)
{
index = 0;
}
setTimeout(“cycle()”,2000);
return;
}
</SCRIPT>
</HEAD>
<BODY onLoad = “select()” onLoad = “cycle()”>
<CENTER>
<IMG NAME=”banner” SRC=”winter2.jpg”>
</CENTER>
<CENTER>
<IMG NAME=”seasons” SRC=”winter.jpg”>
</CENTER>
</BODY>
</HTML>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayDec 21.2006 — You didn't rename the second set of images. Try this:
[code=html]
<HTML>
<HEAD>
<TITLE>HTML and JavaScript</TITLE>
<SCRIPT>
var imgArray = new Array(4);
imgArray[0] = new Image;
imgArray[0].src = "winter2.jpg";
imgArray[1] = new Image;
imgArray[1].src = "spring2.jpg";
imgArray[2] = new Image;
imgArray[2].src = "summer2.jpg";
imgArray[3] = new Image;
imgArray[3].src = "fall2.jpg";
var index = 0;

function select()
{
index = Math.floor(Math.random() * 4);
document.getElementById("banner").src = imgArray[index].src;
setTimeout("select()",1000);
return;
}
var imgSlide = new Array(4);
imgSlide[0] = new Image;
imgSlide[0].src = "winter.jpg";
imgSlide[1] = new Image;
imgSlide[1].src = "spring.jpg";
imgSlide[2] = new Image;
imgSlide[2].src = "summer.jpg";
imgSlide[3] = new Image;
imgSlide[3].src = "fall.jpg";
var index = 0;

function cycle()
{
document.getElementById("seasons").src = imgSlide[index].src;
index++;
if (index == 4)
{
index = 0;
}
setTimeout("cycle()",2000);
return;
}
</SCRIPT>
</HEAD>
<BODY onLoad = "select()" onLoad = "cycle()">
<CENTER>
<IMG id="banner" SRC="winter2.jpg">
</CENTER>
<CENTER>
<IMG id="seasons" SRC="winter.jpg">
</CENTER>
</BODY>
</HTML>
[/code]
Copy linkTweet thisAlerts:
@Mr_JDec 21.2006 — Have to point these out I think

<BODY onLoad = "select()" onLoad = "cycle()">

should be

<BODY onload = "select() ; cycle()">

also the variable index used in function select will conflict with the variable index used in function cycle, change all instances of the second one to index2

Select may be a reserved word
Copy linkTweet thisAlerts:
@TheBearMayDec 21.2006 — Have to point these out I think

<BODY onLoad = "select()" onLoad = "cycle()">

should be

<BODY onload = "select() ; cycle()">

also the variable index used in function select will conflict with the variable index used in function cycle, change all instances of the second one to index2

Select may be a reserved word[/QUOTE]

Good points...
×

Success!

Help @cdweb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...