What I have is a is two sets of images,(Weather , optical) there is about 30 images of is each set.
I have script that will rotate through the images on the main page.
The user is able to view one or the other img sets with a simple onclick
This works great in Mozilla but in IE I get the error document[...]null or not an object, line 95, char 4.
I've spent hours on this, but no luck.
javascript
[code=javascript]
//Declare and set some variables
var type;
var interval = 5000;
var random_display = 0;
var imageArray;
var imageNum = 0;
var totalImages = 0;
//this function is called on page load
//it sets the divs off, looks for a cookie
//turns divs on depending on the cookie
function noDiv() {
//sets both divs display to off
$('weather_pic' ).style.display = 'none';
$('optical_pic' ).style.display = 'none';
//gets the cookie
var ImgCookie = getCookie("pic_ type");
//if cookie is set calls the switchDiv to turn the div display on
//else to defaults to the weather_pic div
if (ImgCookie) {
switchDiv(ImgCo okie);
} else {
switchDiv('weat her_pic');
}
}
//this function turns the divs on or off and sets the cookie accordingly
function switchDiv(picTy pe) {
if (picType == 'weather_pic') {
$('optical_pic' ).style.display = 'none';
$('weather_pic' ).style.display = 'inline';
cookies(picType );
rotate(picType) ;
}
if (picType == 'optical_pic') {
$('weather_pic' ).style.display = 'none';
$('optical_pic' ).style.display = 'inline';
cookies(picType );
rotate(picType) ;
}
}
//this is the set cookie function it deletes the old and sets a new for 30 days
//get, set, and deleteCookie is found in /support/cookie.js
function cookies(picType ) {
deleteCookie("p ic_type");
setCookie("pic_ type", picType, 30);
}
function rotate(picType) {
//var type;
//var interval = 5000;
//var random_display = 0;
//var imageArray = new Array();
//var imageNum = 0;
var i = 0;
if (picType == 'weather_pic') {
var image_dir = "img/revised/";
type = "id_weather ";
imageNum = 0;
imageArray = 0;
imageArray = new Array();
for (i=1; i<=26; i++) {
imageArray[imageNum++] = new imageItem(image _dir + i + ".png");
}
}
if (picType == 'optical_pic') {
var image_dir = "img/Optics/";
type = "id_optical ";
imageNum = 0;
imageArray = 0;
imageArray = new Array();
for (i=1; i<=56; i++) {
imageArray[imageNum++] = new imageItem(image _dir + i + ".jpg");
}
}
totalImages = imageArray.leng th;
switchImage(typ e);
}
function imageItem(image _location) {
this.image_item = new Image();
this.image_item .src = image_location;
}
function switchImage(pla ce) {
var new_image = getNextImage();
document[place].src = new_image;
var recur_call = "switchImage('" +place+"')";
timerID = setTimeout(recu r_call, interval);
}
function getNextImage() {
if (random_display ) {
imageNum = randNum(0, totalImages-1);
} else {
imageNum = (imageNum+1) % totalImages;
}
var new_image = get_ImageItemLo cation(imageArr ay[imageNum]);
return(new_imag e);
}
function randNum(x, y) {
var range = y - x + 1;
return Math.floor(Math .random() * range) + x;
}
function get_ImageItemLo cation(imageObj ) {
return(imageObj .image_item.src )
}
[/code]
noDiv() is called from the page load and the java works from there.
This problem is in my switchDiv() function, but I haven't been able to solve it.
here is the html
[code=html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script type="text/javascript" src="support/cookie.js"></script>
<script type="text/javascript" src="support/main.js"></script>
</head>
<body onload="noDiv() ">
<div id="navtrail2" >
<span onclick="switch Div('weather_pi c')"> Weather Pictures</span> :
<span onclick="switch Div('optical_pi c')"> Optical Pictures</span>
</div>
<!-- Start right Column box -->
<div id="righcolbox" >
<div id="weather_pic ">
<img height="385px" width="385px" align="right" border="3" id="id_weather " src="img/revised/1.png" alt="Weather Images" />
</div>
<div id="optical_pic ">
<img height="385px" width="385px" align="right" border="3" id="id_optical " src="img/Optics/1.jpg" alt="Optical Images" />
</div>
<!-- End right Column box -->
</div>
</body>
</html>
[/code]
could someone help with this?
I have script that will rotate through the images on the main page.
The user is able to view one or the other img sets with a simple onclick
This works great in Mozilla but in IE I get the error document[...]null or not an object, line 95, char 4.
I've spent hours on this, but no luck.
javascript
[code=javascript]
//Declare and set some variables
var type;
var interval = 5000;
var random_display = 0;
var imageArray;
var imageNum = 0;
var totalImages = 0;
//this function is called on page load
//it sets the divs off, looks for a cookie
//turns divs on depending on the cookie
function noDiv() {
//sets both divs display to off
$('weather_pic' ).style.display = 'none';
$('optical_pic' ).style.display = 'none';
//gets the cookie
var ImgCookie = getCookie("pic_ type");
//if cookie is set calls the switchDiv to turn the div display on
//else to defaults to the weather_pic div
if (ImgCookie) {
switchDiv(ImgCo okie);
} else {
switchDiv('weat her_pic');
}
}
//this function turns the divs on or off and sets the cookie accordingly
function switchDiv(picTy pe) {
if (picType == 'weather_pic') {
$('optical_pic' ).style.display = 'none';
$('weather_pic' ).style.display = 'inline';
cookies(picType );
rotate(picType) ;
}
if (picType == 'optical_pic') {
$('weather_pic' ).style.display = 'none';
$('optical_pic' ).style.display = 'inline';
cookies(picType );
rotate(picType) ;
}
}
//this is the set cookie function it deletes the old and sets a new for 30 days
//get, set, and deleteCookie is found in /support/cookie.js
function cookies(picType ) {
deleteCookie("p ic_type");
setCookie("pic_ type", picType, 30);
}
function rotate(picType) {
//var type;
//var interval = 5000;
//var random_display = 0;
//var imageArray = new Array();
//var imageNum = 0;
var i = 0;
if (picType == 'weather_pic') {
var image_dir = "img/revised/";
type = "id_weather ";
imageNum = 0;
imageArray = 0;
imageArray = new Array();
for (i=1; i<=26; i++) {
imageArray[imageNum++] = new imageItem(image _dir + i + ".png");
}
}
if (picType == 'optical_pic') {
var image_dir = "img/Optics/";
type = "id_optical ";
imageNum = 0;
imageArray = 0;
imageArray = new Array();
for (i=1; i<=56; i++) {
imageArray[imageNum++] = new imageItem(image _dir + i + ".jpg");
}
}
totalImages = imageArray.leng th;
switchImage(typ e);
}
function imageItem(image _location) {
this.image_item = new Image();
this.image_item .src = image_location;
}
function switchImage(pla ce) {
var new_image = getNextImage();
document[place].src = new_image;
var recur_call = "switchImage('" +place+"')";
timerID = setTimeout(recu r_call, interval);
}
function getNextImage() {
if (random_display ) {
imageNum = randNum(0, totalImages-1);
} else {
imageNum = (imageNum+1) % totalImages;
}
var new_image = get_ImageItemLo cation(imageArr ay[imageNum]);
return(new_imag e);
}
function randNum(x, y) {
var range = y - x + 1;
return Math.floor(Math .random() * range) + x;
}
function get_ImageItemLo cation(imageObj ) {
return(imageObj .image_item.src )
}
[/code]
noDiv() is called from the page load and the java works from there.
This problem is in my switchDiv() function, but I haven't been able to solve it.
here is the html
[code=html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script type="text/javascript" src="support/cookie.js"></script>
<script type="text/javascript" src="support/main.js"></script>
</head>
<body onload="noDiv() ">
<div id="navtrail2" >
<span onclick="switch Div('weather_pi c')"> Weather Pictures</span> :
<span onclick="switch Div('optical_pi c')"> Optical Pictures</span>
</div>
<!-- Start right Column box -->
<div id="righcolbox" >
<div id="weather_pic ">
<img height="385px" width="385px" align="right" border="3" id="id_weather " src="img/revised/1.png" alt="Weather Images" />
</div>
<div id="optical_pic ">
<img height="385px" width="385px" align="right" border="3" id="id_optical " src="img/Optics/1.jpg" alt="Optical Images" />
</div>
<!-- End right Column box -->
</div>
</body>
</html>
[/code]
could someone help with this?
Comment