Hello,
I was wondering if someone couldhelp me please. I dont really know javascript and how to modify it and I was wondering if someone could show me how to modify my script please.
I have a basic html website and would like to display two images on each page. On page refresh both images would change. I have found the following code which seems to work for one set of images but how can I get the other set to work as well?
Below is a stripped down version of my html.Code:<script type="text/javascript"> function loadNextImage() { //get image object var myImg = document.getElementById('CImage'); //declare image directory path and image array var thePath = "images/"; var theImages = new Array(); theImages[0]="C1.jpg"; theImages[1]="C2.jpg"; theImages[2]="C3.jpg"; theImages[3]="C4.jpg"; theImages[4]="C5.jpg"; theImages[5]="C6.jpg"; //get current cookie value var currentIndex = parseInt(getCookie()); var imgPath = thePath + theImages[currentIndex]; myImg.src = imgPath; myImg.alt = theImages[currentIndex]; myImg.title = theImages[currentIndex]; //set next cookie index currentIndex += 1; if(currentIndex > (theImages.length - 1)) { currentIndex = 0; } setCookie(currentIndex); } function setCookie(someint) { var now = new Date(); var addDays = now.getDate() + 7 now.setDate(addDays); // cookie expires in 7 days var theString = 'imgID=' + escape(someint) + ';expires=' + now.toUTCString(); document.cookie = theString; } function getCookie() { var output = "0"; if(document.cookie.length > 0) { var temp = unescape(document.cookie); temp = temp.split(';'); for(var i = 0; i < temp.length; i++) { if(temp[i].indexOf('imgID') != -1) { temp = temp[i].split('='); output = temp.pop(); break; } } } return output; } </script>
I would like to display a new aray of images in ID Limage soCode:<body onload="loadNextImage();"> <div id="left"> <img id="CImage" src="" alt="" title=""/> <img id="LImage" src="" alt="" title=""/> </div> </body>
How do I get the two image areas to display and and refresh in the orders above on each page refresh. I hope I've provided enough information.Code:var myImg = document.getElementById('LImage'); //declare image directory path and image array var thePath = "images/"; var theImages = new Array(); theImages[0]="L1.jpg"; theImages[1]="L2.jpg"; theImages[2]="L3.jpg"; theImages[3]="L4.jpg"; theImages[4]="L5.jpg"; theImages[5]="L6.jpg"; theImages[6]="L7.jpg";
Thanks in advance for any help
Jane




Reply With Quote

Bookmarks