473,322 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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(place). 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 1955
pbmods
5,821 Expert 4TB
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 Expert Mod 8TB
Which is line 48 ?
Aug 20 '07 #3
epots9
1,351 Expert 1GB
the variable place (that u use here: switchImage(place)), what is it? what is it referencing?
Aug 20 '07 #4
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
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...
5
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...
12
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...
136
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...
0
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...
5
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...
0
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...
20
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 =...
10
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: ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.