hello, i have what i think is a novice javascript problem, all help is appreciated.

i'm trying to run a couple of the same scripts with different arrays on the same page. the scripts are running fine, the problem is they're both grabbing from one array. normally these scripts live on two different .html includes, but for demo purposes i've combined them on to this one page. advice, thanks.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body onload="rotater();rotater2()">

<script type="text/javascript">
var howOften = 20; //number often in seconds to rotate
var current = 0; //start the counter at 0
var ns6 = document.getElementById&&!document.all; //detect netscape 6

// images, text, etc in the array elements
var items = new Array();
items[0] = "<div id='testpic'>"
+ "<img src='img/testimonial_3.gif' width='239' height='133' />"
+ "</div>"
+ "<div class='testtext14green'>"
+ "“Atempo Live Backup was the only backup product capable of easily meeting all of our data protection objectives with out of the box Xsan support.”"
+ "</div>"
+ "<div class='testtext12green'>"
+ "Mark Miranda, IT Director The Cimarron Group"
+ "<br /><br />"
+ "</div>";

items[1] = "<div id='testpic'>"
+ "<img src='img/testimonial_3_red.gif' width='239' height='133' />"
+ "</div>"
+ "<div class='testtext14red'>"
+ "“Atempo Live Backup was the only backup product capable of easily meeting all of our data protection objectives with out of the box Xsan support.”"
+ "</div>"
+ "<div class='testtext12red'>"
+ "Mark Miranda, IT Director The Cimarron Group"
+ "<br /><br />"
+ "</div>";


function rotater() {
if(document.layers) {
document.placeholderlayer.document.write(items[current]);
document.placeholderlayer.document.close();
}
if(ns6)document.getElementById("placeholderdiv").innerHTML=items[current]
if(document.all)
placeholderdiv.innerHTML=items[current];

current = (current==items.length-1) ? 0 : current+1; //increment or reset
setTimeout("rotater()",howOften*1000);
}
function randOrd() {
return (Math.round(Math.random())-0.5);
}
items.sort( randOrd );
</script>


<div id="placeholderdiv"></div>


<script type="text/javascript">
var howOften = 20; //number often in seconds to rotate
var current = 0; //start the counter at 0
var ns6 = document.getElementById&&!document.all; //detect netscape 6

// images, text, etc in the array elements
var items = new Array();
items[0] = "<div id='solImage2'>"
+ "<img src='img/solutions_govt.gif' alt='Solutions for Government'/>"
+ "</div>"
+ "<div class='solTextHdRed'>"
+ "Solutions for Government"
+ "</div>"
+ "<div class='soltext12Red'>"
+ "Insert text here that has information for Solutions for Government<br />"
+ "<br />"
+ "<a class='white12' href='.html'>Find out more</a> "
+ "<a href='.html'><img class='findmore' src='img/arrow.gif' border='0'/></a>"
+ "<br /><br />"
+ "</div>";

items[1] = "<div id='solImage2'>"
+ "<img src='img/solutions_financial.gif' alt='Solutions for Financial Services'/>"
+ "</div>"
+ "<div class='solTextHdGrn'>"
+ "Solutions for Financial Services"
+ "</div>"
+ "<div class='soltext12Grn'>"
+ "Insert text here that has information for Solutions for Financial Services<br />"
+ "<br />"
+ "<a class='white12' href='.html'>Find out more</a> "
+ "<a href='.html'><img class='findmore' src='img/arrow.gif' border='0'/></a>"
+ "<br /><br />"
+ "</div>";


function rotater2() {
if(document.layers) {
document.placeholderlayer.document.write(items[current]);
document.placeholderlayer.document.close();
}
if(ns6)document.getElementById("placeholderdiv2").innerHTML=items[current]
if(document.all)
placeholderdiv2.innerHTML=items[current];

current = (current==items.length-1) ? 0 : current+1; //increment or reset
setTimeout("rotater2()",howOften*1000);
}
function randOrd2() {
return (Math.round(Math.random())-0.5);
}
items.sort( randOrd2 );
</script>

<span id="placeholderdiv2"></span>


</body>
</html>

try working with concrete divs instead of in-memory ones. play around with their visibility or display attributes if you wish, other wise your mark-up seems so confusing. and i suggest creating your array with the div ids or the div objects like :
items[0] = document.getElementById('foo');
then you can work with them more easily
Serkan Şendur

This article has been dead for over six months. Start a new discussion instead.