473,780 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'document[...]' is null or not an object with rotating images

27 New Member
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
Expand|Select|Wrap|Line Numbers
  1. //Declare and set some variables
  2. var type;
  3. var interval = 5000;
  4. var random_display = 0;
  5. var imageArray;
  6. var imageNum = 0;
  7. var totalImages = 0;
  8.  
  9. //this function is called on page load
  10. //it sets the divs off, looks for a cookie 
  11. //turns divs on depending on the cookie
  12. function noDiv() {
  13.    //sets both divs display to off
  14.    $('weather_pic').style.display = 'none';
  15.    $('optical_pic').style.display = 'none';
  16.  
  17.    //gets the cookie 
  18.    var ImgCookie = getCookie("pic_type");
  19.  
  20.    //if cookie is set calls the switchDiv to turn the div display on
  21.    //else to defaults to the weather_pic div
  22.    if (ImgCookie) {
  23.       switchDiv(ImgCookie);
  24.    } else {
  25.       switchDiv('weather_pic');
  26.    }
  27. }
  28.  
  29. //this function turns the divs on or off and sets the cookie accordingly
  30. function switchDiv(picType) {
  31.    if (picType == 'weather_pic') {
  32.       $('optical_pic').style.display = 'none';
  33.       $('weather_pic').style.display = 'inline';
  34.       cookies(picType);
  35.       rotate(picType);
  36.    }
  37.    if (picType == 'optical_pic') {
  38.       $('weather_pic').style.display = 'none';
  39.       $('optical_pic').style.display = 'inline';
  40.       cookies(picType);
  41.       rotate(picType);
  42.    }
  43. }
  44.  
  45. //this is the set cookie function it deletes the old and sets a new for 30 days 
  46. //get, set, and deleteCookie is found in /support/cookie.js
  47. function cookies(picType) {
  48.    deleteCookie("pic_type");
  49.    setCookie("pic_type", picType, 30);
  50. }
  51. function rotate(picType) {
  52.    //var type;
  53.    //var interval = 5000;
  54.    //var random_display = 0;
  55.    //var imageArray = new Array();
  56.    //var imageNum = 0;
  57.    var i = 0;
  58.  
  59.    if (picType == 'weather_pic') {
  60.       var image_dir = "img/revised/";
  61.       type = "id_weather";
  62.       imageNum = 0;
  63.       imageArray = 0;
  64.       imageArray = new Array();
  65.  
  66.       for (i=1; i<=26; i++) {
  67.          imageArray[imageNum++] = new imageItem(image_dir + i + ".png");
  68.       }
  69.    }
  70.    if (picType == 'optical_pic') {
  71.       var image_dir = "img/Optics/";
  72.       type = "id_optical";
  73.       imageNum = 0;
  74.       imageArray = 0;
  75.       imageArray = new Array();
  76.  
  77.       for (i=1; i<=56; i++) {
  78.          imageArray[imageNum++] = new imageItem(image_dir + i + ".jpg");
  79.       }
  80.    }
  81.  
  82.    totalImages = imageArray.length;
  83.    switchImage(type);
  84. }
  85.  
  86. function imageItem(image_location) {
  87.    this.image_item = new Image();
  88.    this.image_item.src = image_location;
  89. }
  90.  
  91. function switchImage(place) {
  92.    var new_image = getNextImage();
  93.    document[place].src = new_image;
  94.    var recur_call = "switchImage('"+place+"')";
  95.    timerID = setTimeout(recur_call, interval);
  96. }
  97. function getNextImage() {
  98.    if (random_display) {
  99.       imageNum = randNum(0, totalImages-1);
  100.    } else {
  101.       imageNum = (imageNum+1) % totalImages;
  102.    }
  103.  
  104.    var new_image = get_ImageItemLocation(imageArray[imageNum]);
  105.    return(new_image);
  106. }
  107.  
  108. function randNum(x, y) {
  109.    var range = y - x + 1;
  110.    return Math.floor(Math.random() * range) + x;
  111. }
  112.  
  113. function get_ImageItemLocation(imageObj) {
  114.    return(imageObj.image_item.src)
  115. }
  116.  
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

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  3. <head>
  4. <script type="text/javascript" src="support/cookie.js"></script>
  5. <script type="text/javascript" src="support/main.js"></script>
  6. </head>
  7. <body onload="noDiv()">
  8.             <div id="navtrail2">
  9.                <span onclick="switchDiv('weather_pic')"> Weather Pictures</span> :
  10.                <span onclick="switchDiv('optical_pic')"> Optical Pictures</span>
  11.             </div>
  12.                <!-- Start right Column box -->
  13.                <div id="righcolbox">
  14.                   <div id="weather_pic">
  15.                      <img height="385px" width="385px" align="right" border="3" id="id_weather" src="img/revised/1.png" alt="Weather Images" />
  16.                   </div>
  17.                   <div id="optical_pic">
  18.                      <img height="385px" width="385px" align="right" border="3" id="id_optical" src="img/Optics/1.jpg" alt="Optical Images" />
  19.                   </div>
  20.  
  21.                <!-- End right Column box -->
  22.                </div>
  23. </body>
  24. </html>
  25.  
could someone help with this?
Aug 21 '07
11 2154
bdbeames
27 New Member
Ok, give me some credit. I had it at .png, I changed it because that wouldn't work. I want to use .png images so I'll play with it until I figure it out.

thanks for the help
Aug 21 '07 #11
pbmods
5,821 Recognized Expert Expert
Heya, BD.

lol I figured. I had to point it out, though, because in your OP, one set was .jpg, while the other was .png.
Aug 21 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
10113
by: Winfried Koenig | last post by:
Hi everyone, I have a main page: -------------------------------------------------- <html><head><title>Test</title> </head><body> <img id="img_a" name="img_a" src="image_1.png" alt=""><br>
14
14189
by: Chris | last post by:
Heres my problem: <a href="javascript:void(document.buysell.submit())" target="_parent" onMouseOver="MM_swapImage('members','','images/membersf2.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="images/members.gif" alt="Back to members page" name="members" width="270" height="25" border="0"></a> I get the error "document.buysell" is null or not an object, but my form name is buysell and when using the submit button, which is not
2
1952
by: Aaron | last post by:
Hi, I've seen javascript code where a constructor function is passed an argument "document", and inside the function itself the assignment "this.document = document;" is made. This is the code (or the part necessary for the example): function ToggleButton(document) { ToggleButton.images = new Array(4); for(i=0;i<4;i++) { ToggleButton.images = new
5
2102
by: John | last post by:
I am rotating images at one location of my web site. My problem is if I set the width and height of the new image before I show the new image, the old image is stretched first to the new image dimensions, and if I show the new image before setting its dimensions, the new image is stretched first to the old image dimension before it is adjusted to its own dimension. I would like to load a new image with its own dimension at the same time....
1
3230
by: Sandy Bremmer | last post by:
I have seen many Javascripts that rotate images with each load or refresh of the page but so far all I've found require hard coding the image filename into the script. Does anyone know of a script that pulls images randomly from a directory? Thus I would need only add (or delete) images from that directory and they would display on the web page respectively. All the images are the same size (90x90) but there are hundreds so hard coding...
136
9457
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
4
1975
by: bdbeames | last post by:
Could someone help with this? I currently have a rotating picture that I have on our website's main page. This week we decided to add another set of pictures for users to view. The users can switch between the two different picture sets by a simple onclick where I change the picture sets. I started to modify my existing code and ran into the problem where the img within a div is not loading in IE, it works fine in Mozilla but in IE I...
10
3770
by: AC | last post by:
I had a page that does some event setup on window.onload: function prepEvents() { document.getElementById("menumap_sales").onmouseover = swapMenuSales; // etc } window.onload = prepEvents;
5
4014
by: ankit1999 | last post by:
I have a problem, everytime i'm run this page http://click2travel.in/index.php i get the this error,,,
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.