User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,649 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,874 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 567 | Replies: 1
Reply
Join Date: Jan 2008
Posts: 1
Reputation: moestavern is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
moestavern moestavern is offline Offline
Newbie Poster

two scripts beat as one

  #1  
Jan 29th, 2008
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>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: istanbul
Posts: 264
Reputation: serkansendur is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 23
serkansendur's Avatar
serkansendur serkansendur is offline Offline
Posting Whiz in Training

Re: two scripts beat as one

  #2  
Jan 30th, 2008
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
Serkan Şendur
MCAD.NET
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 1:20 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC