I've been working on this for hours and I'm just lost.
I need for it to display a random image, but a different one each time the page loads. Here's what I have. All I want to know is if I'm even on the right track. I'm about to give up.
<html>
<head>
<script type="text/javascript">
var images = new Array("images/pic1.jpg", "images/pic2.jpg", "images/pic3.jpg", "images/pic4.jpg", "images/pic5.jpg", "images/pic6.jpg");
function makeCookie() {
var idx = Math.floor((Math.random()* 6));
document.cookie="last=" + idx;
}
function dont() {
var lastinx=document.cooke.indexOf("last=");
if(lastidx != -1) {
var begin = lastidx + 5;
var end = document.cookie.indexOf(";", begin);
if(end == -1) { end=document.cookie.length;}
whichpic = unescape(document.cookie.substring(begin, end));
if(whichpic <6) {
idx = whichpic +1;}
else {
idx = 1;}
function displayimage() {
document.write("<img src='"+images[idx]+"'>");
}
</script>
</head>
<body onLoad="makeCookie(), dont()">
<script type="text/javascript">
displayimage();
</script>
</body>
</html>
I need for it to display a random image, but a different one each time the page loads. Here's what I have. All I want to know is if I'm even on the right track. I'm about to give up.
<html>
<head>
<script type="text/javascript">
var images = new Array("images/pic1.jpg", "images/pic2.jpg", "images/pic3.jpg", "images/pic4.jpg", "images/pic5.jpg", "images/pic6.jpg");
function makeCookie() {
var idx = Math.floor((Math.random()* 6));
document.cookie="last=" + idx;
}
function dont() {
var lastinx=document.cooke.indexOf("last=");
if(lastidx != -1) {
var begin = lastidx + 5;
var end = document.cookie.indexOf(";", begin);
if(end == -1) { end=document.cookie.length;}
whichpic = unescape(document.cookie.substring(begin, end));
if(whichpic <6) {
idx = whichpic +1;}
else {
idx = 1;}
function displayimage() {
document.write("<img src='"+images[idx]+"'>");
}
</script>
</head>
<body onLoad="makeCookie(), dont()">
<script type="text/javascript">
displayimage();
</script>
</body>
</html>