doubledtx Posted February 14, 2014 Share Posted February 14, 2014 Howdy, I am trying to place three instances of a 'scrpt' on my page to rotate the same three banners in different orders, when I put it in the second time I get a background but no banners. can anyone tell me what I am doing wrong or how to make it work (changed the link names for privacy) <p> <script language="JavaScript1.2">var variableslide=new Array()variableslide[0]=['Images/image1.gif','Http://www.msn.com',']variableslide[1]= ['Images/image2.gif','Http://www.msn.com',']variableslide[2]= ['Images/image3.gif','Http://www.msn.com',']var slidewidth='320x'var slideheight='50px'var slidebgcolor='#252A54'var slidedelay=7000var ie=document.allvar dom=document.getElementByIdfor (i=0;i<variableslide.length;i++){var cacheimage=new Image()cacheimage.src=variableslide[0]}var currentslide=0function rotateimages(){contentcontainer='<center>'if (variableslide[currentslide][1]!="")contentcontainer+='<a href="'+variableslide[currentslide][1]+'">'contentcontainer+='<img src="'+variableslide[currentslide][0]+'" border="0" vspace="3">'if (variableslide[currentslide][1]!="")contentcontainer+='</a>'contentcontainer+='</center>'if (variableslide[currentslide][2]!="")contentcontainer+=variableslide[currentslide][2]if (document.layers){crossrotateobj.document.write(contentcontainer)crossrotateobj.document.close()}else if (ie||dom)crossrotateobj.innerHTML=contentcontainerif (currentslide==variableslide.length-1) currentslide=0else currentslide++setTimeout("rotateimages()",slidedelay)}if (ie||dom)document.write('<div id="slidedom" style="width:'+slidewidth+';height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>')function start_slider(){crossrotateobj=dom? document.getElementById("slidedom") : ie? document.all.slidedom : document.slidensmain.document.slidenssubif (document.layers)document.slidensmain.visibility="show"rotateimages()}if (ie||dom)start_slider()else if (document.layers)window.onload=start_slider</script><ilayer id="slidensmain" width=&{slidewidth}; height=&{slideheight}; bgColor=&{slidebgcolor}; visibility=hide><layer id="slidenssub" width=&{slidewidth}; left=0 top=0></layer></ilayer> </p> Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/ Share on other sites More sharing options...
jazzman1 Posted February 15, 2014 Share Posted February 15, 2014 Can I see the values of the src to those images? <img src="'+variableslide[currentslide][0] /> Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1468978 Share on other sites More sharing options...
doubledtx Posted February 15, 2014 Author Share Posted February 15, 2014 Not sure what you mean, the code is as i found it. (I am not fluent in js) the sourse i guess would be Images/imagename.gif? Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1468979 Share on other sites More sharing options...
jazzman1 Posted February 15, 2014 Share Posted February 15, 2014 Use view-source scheme in your web browser and tell us what result do you see there. It would be something like Images/imagename.gif. Or....post the view-source document here using [ code ] tags. Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1468980 Share on other sites More sharing options...
doubledtx Posted February 15, 2014 Author Share Posted February 15, 2014 Here is the file I am working from if that helpspage.html Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1468985 Share on other sites More sharing options...
kicken Posted February 15, 2014 Share Posted February 15, 2014 I'd suggest you find some updated code that does what you want. That code is like late-90's era (NS4/IE5) code. Aside from being old it's not written in such a way that you can just copy and paste multiple copies of it into a page. You'd need to rewrite it to remove it's dependence on global variables for that to work. Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1468986 Share on other sites More sharing options...
doubledtx Posted February 15, 2014 Author Share Posted February 15, 2014 Ah, I am like so java illiterate. Any suggestions as to where I might find what I need? Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1468988 Share on other sites More sharing options...
jazzman1 Posted February 15, 2014 Share Posted February 15, 2014 (edited) Try, page.html <!DOCTYPE html> <html lang="en"> <head> <script type="text/javascript" src="js/rotate.js"></script> <title>Banner test page</title> </head> <body> <div> <a href="http://msn.com"> <img src="Images/1.jpg" alt="some image" id="adBanner" /> </a> </div> </body> </html> Images folder (images/) image1.gif image2.gif image3.gif rotate.js (js/rotate.js) window.onload = choosePic; var adImages = new Array("Images/image1.gif","Images/image2.gif","Images/image3.gif"); function rotate() { thisAd++; if (thisAd == adImages.length) { thisAd = 0; } document.getElementById("adBanner").src = adImages[thisAd]; setTimeout("rotate()", 3 * 1000); } function choosePic() { thisAd = Math.floor((Math.random() * adImages.length)); document.getElementById("adBanner").src = adImages[thisAd]; rotate(); } Edited February 15, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1468999 Share on other sites More sharing options...
doubledtx Posted February 15, 2014 Author Share Posted February 15, 2014 Got that to work on one instance on the page, but how would I add a second and third Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1469008 Share on other sites More sharing options...
jazzman1 Posted February 15, 2014 Share Posted February 15, 2014 JavaScript is an Object-Oriented Programming? Where did you stuck? Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1469010 Share on other sites More sharing options...
doubledtx Posted February 15, 2014 Author Share Posted February 15, 2014 Not sure what you are asking there. I am stuck at trying to figure out how to replicate the code a second and third time on the page and get the banners to show up Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1469014 Share on other sites More sharing options...
jazzman1 Posted February 15, 2014 Share Posted February 15, 2014 Sorry, I'm not here to write all code for you. It was a simple example how to make some picture rotation using js. Everything you need is, to pick up some js slideshow library with a banner rotation. Take a look at those examples. Quote Link to comment https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/#findComment-1469026 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.