Allen Pitts
asked on
Array next object
Hello expert,
Thought I could get the next object in an array by
calling the array with [+1} next to it. But its not working.
How can I get the next array item. Full code below.
Thanks.
Allen in Dallas
<html>
<head>
<style type="text/css">
body {font-family: arial;}
</style>
<script type="text/javascript">
function ChangeIt()
{
var colors;
colors = new Array("red", "blue", "green", "yellow", "purple");
document.body.style.backgr oundColor = colors[0];
var t = setInterval(function() {
document.body.style.backgr oundColor = colors[+1];
}, 3000);
}
</script>
</head>
<body>
This page begins with a red background and
changes the body background after three seconds.
The Javascript
function is set in header section and called
from the body.
</body>
<script type="text/javascript">
ChangeIt();
</script>
</body>
</html>
Thought I could get the next object in an array by
calling the array with [+1} next to it. But its not working.
How can I get the next array item. Full code below.
Thanks.
Allen in Dallas
<html>
<head>
<style type="text/css">
body {font-family: arial;}
</style>
<script type="text/javascript">
function ChangeIt()
{
var colors;
colors = new Array("red", "blue", "green", "yellow", "purple");
document.body.style.backgr
var t = setInterval(function() {
document.body.style.backgr
}, 3000);
}
</script>
</head>
<body>
This page begins with a red background and
changes the body background after three seconds.
The Javascript
function is set in header section and called
from the body.
</body>
<script type="text/javascript">
ChangeIt();
</script>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello COBOL,
I found it
i=(i>=color.length) ? 0 : i+1;
should be
i=(i>=colors.length) ? 0 : i+1;
Works now
Thanks.
Allen
I found it
i=(i>=color.length) ? 0 : i+1;
should be
i=(i>=colors.length) ? 0 : i+1;
Works now
Thanks.
Allen
ASKER
Thanks for the excellent answer.
in the expression
i=(i>=colors.length) ? 0 : i+1;
It says if I is greater than the length of the array then set i back to 1
Correct?
in the expression
i=(i>=colors.length) ? 0 : i+1;
It says if I is greater than the length of the array then set i back to 1
Correct?
ASKER
Thanks for the help.
I inserted your excellent script
into the page with no result.
I'll bet its just a syntax error but
I can't find it.
Thanks
Allen in Dallas
change-j.html