473,779 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'document[...]' is null or not an object

27 New Member
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 get the error 'document[...]'is null or not an object, line:48, char:4.

Here is a copy of my javascript
Expand|Select|Wrap|Line Numbers
  1.   3 //declares the cookie
  2.   4 var ImgCookie;
  3.   5 
  4.   6 //declaressets the path
  5.   7 var image_dir = "img/revised/";
  6.   8 
  7.   9 //declares array starting index
  8.  10 var imageNum = 0;
  9.  11 
  10.  12 //declares an img array
  11.  13 imageArray = new Array();
  12.  14 
  13.  15 //loops through all images and adds to the array
  14.  16 for (i=1; i<=26; i++) {
  15.  17       imageArray[imageNum++] = new imageItem(image_dir + i + ".png");
  16.  18 }
  17.  19 
  18.  20 var time_interval = 5000;
  19.  21 var random_display = 0;//set to false so that the images are displayed in order
  20.  22 
  21.  23 
  22.  24 function choose_id() {
  23.  25       $('weather_pic').style.display = 'none';
  24.  26       $('optical_pic').style.display = 'none';
  25.  27 
  26.  28       ImgCookie = getCookie('pic_type');
  27.  29 
  28.  30       if (ImgCookie) {
  29.  31          switchImage(ImgCookie);
  30.  32       } else {
  31.  33          cook('weather_pic');
  32.  34       }
  33.  35       //switchImage('weather_pic');
  34.  36 }
  35.  37 
  36.  38 function switchImage(place) {
  37.  39       if (place == "weather_pic") {
  38.  40          $('weather_pic').style.display = 'inline';
  39.  41       }
  40.  42       if (place == 'optical_pic') {
  41.  43          $('weather_pic').style.display = 'inline';
  42.  44       }
  43.  45 
  44.  46       var new_image = getNextImage();
  45.  47       document[place].src = new_image;
  46.  48       var recur_call = "switchImage('"+place+"')";
  47.  49       timerID = setTimeout(recur_call, time_interval);
  48.  50 }
  49.  51 
  50.  52 function cook(pictype) {
  51.  53       var type = pictype;
  52.  54       deleteCookie("pic_type");
  53.  55       setCookie("pic_type", type, 30);
  54.  56 
  55.  57       choose_id();
  56.  58 }
  57.  
  58.  60 function getNextImage() {
  59.  61       if (random_display) {
  60.  62          imageNum = randNum(0, totalImages-1);
  61.  63       } else {
  62.  64          imageNum = (imageNum+1) % totalImages;
  63.  65       }
  64.  66 
  65.  67       var new_image = get_ImageItemLocation(imageArray[imageNum]);
  66.  68       return(new_image);
  67.  69 }
  68.  70 var totalImages = imageArray.length;
  69.  71 
  70.  72 function imageItem(image_location) {
  71.  73       this.image_item = new Image();
  72.  74       this.image_item.src = image_location;
  73.  75 }
  74.  76 
  75.  77 function get_ImageItemLocation(imageObj) {
  76.  78       return(imageObj.image_item.src)
  77.  79 }
  78.  80 
  79.  81 function randNum(x, y) {
  80.  82       var range = y - x + 1;
  81.  83       return Math.floor(Math.random() * range) + x;
  82.  84 }
  83.  85 
  84.  86 
  85.  87 function getPrevImage() {
  86.  88       imageNum = (imageNum-1) % totalImages;
  87.  89       var new_image = get_ImageItemLocation(imageArray[imageNum]);
  88.  90       return(new_image);
  89.  91 }
  90.  92 
  91.  93 function prevImage(place) {
  92.  94       var new_image = getPrevImage();
  93.  95       document[place].src = new_image;
  94.  96 }
I am calling choose _id() when the page loads and then depending on a cookie that is set or not I go from there. One id or the other should be displayed depending on the cookie. The script is not complete, but it should work if there is no cookie set from the start. The problem I believe is in my function switchImage(pla ce). I haven't used javascript that much so if someone see a better way around all of this let me know.

here is the html
Expand|Select|Wrap|Line Numbers
  1.  <!-- Start right Column box -->
  2.    <div id="righcolbox">
  3.       <div>
  4.          <img height="385px" width="385px" align="right" id="weather_pic" border="3" src="img/revised/1.png" alt="Weather Images" />
  5.          <img height="385px" width="385px" align="right" id="optical_pic" border="3" src="img/Optical/1.png" alt="Optical Images" />
  6.       </div>
  7.    <!-- End right Column box -->
  8.    </div>
  9.  
If you care to look at the site it is http://beta.climate.usurf.usu.edu

thanks again
Aug 20 '07 #1
4 1975
pbmods
5,821 Recognized Expert Expert
Heya, bdbeames.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Aug 20 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
Which is line 48 ?
Aug 20 '07 #3
epots9
1,351 Recognized Expert Top Contributor
the variable place (that u use here: switchImage(pla ce)), what is it? what is it referencing?
Aug 20 '07 #4
bdbeames
27 New Member
place comes from choose_id()

The value will be the cookie I store, and it will determine which img set will be used.

see the html it will be the id for weather_pic or the id for optical_pic
Aug 20 '07 #5

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

Similar topics

6
6846
by: David List | last post by:
I'm having a problem using different properties of the document object in the example javascripts in my textbook with browsers that identify themselves as using the Mozilla engine. One example of these problems is using document.layers. I have Google'd for examples of how to use the document object specifically with Mozilla, but I cannot find anything that explains why my problems occur. Could anyone here see through the included example...
5
3524
by: James Moe | last post by:
Hello, 1. The document.all property (array?) seems to be a popular IE-only attribute. Other browsers (Opera, Mozilla) do not seem to care for it which, of course, occasionally produces weird displays and non-functional links. Is it, indeed, a IE-ism? 2. While experimenting with the elusive document.all, I ran into a sort of catch-22, it least with Mozilla. I tried testing (null == document.all) to decide if the property exists, and get...
12
10176
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical scrollbar, you get the height of the entire document, screwing up any chance of centering a window in the browser using these values. Is there a way to get the height of the actual browser window and not the entire page height? Thanks.
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,...
0
1381
by: John Smith | last post by:
Hey folks, I'm creating an MS Word document in a C# Windows application. Because the client base has so many different versions of Word they are using, I opted to go with late binding to create the document. **Everything works great, but I can't figure out how to do 2 things: 1) Double Spacing 2) Insert a Page Break
5
6695
by: John Smith | last post by:
Hey folks, I'm creating an MS Word document in a C# Windows application. Because the client base has so many different versions of Word they are using, I opted to go with late binding to create the document. **Everything works great, but I can't figure out how to do 2 things: 1) Double Spacing 2) Insert a Page Break
0
3947
by: volume | last post by:
Hi all, In an effort to try to impress the boss, I would like to log accounting information to an Excel spreadsheet using C# and .NET. This would be a mockup only, not a real solution - yet! We are a small ticketing company - not a bunch of IT whiz kids. ...but I do have an IT background. I have been successful in logging (printing) tickets to a word document, and it all works kinda cool. However, I wish to log to same information to...
20
7012
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt = document.getElementById('hometab'); Has anyone ever seen anything like this before, or am I dreaming?
10
8815
by: Simon Brooke | last post by:
The DOM API has included public Node importNode(Node,boolean) as a method of the Document interface for a long time. Does anything actually implement it? Xerces 2 is giving me: org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation. at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source) at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source)
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...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.