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 -
3 //declares the cookie
-
4 var ImgCookie;
-
5
-
6 //declaressets the path
-
7 var image_dir = "img/revised/";
-
8
-
9 //declares array starting index
-
10 var imageNum = 0;
-
11
-
12 //declares an img array
-
13 imageArray = new Array();
-
14
-
15 //loops through all images and adds to the array
-
16 for (i=1; i<=26; i++) {
-
17 imageArray[imageNum++] = new imageItem(image_dir + i + ".png");
-
18 }
-
19
-
20 var time_interval = 5000;
-
21 var random_display = 0;//set to false so that the images are displayed in order
-
22
-
23
-
24 function choose_id() {
-
25 $('weather_pic').style.display = 'none';
-
26 $('optical_pic').style.display = 'none';
-
27
-
28 ImgCookie = getCookie('pic_type');
-
29
-
30 if (ImgCookie) {
-
31 switchImage(ImgCookie);
-
32 } else {
-
33 cook('weather_pic');
-
34 }
-
35 //switchImage('weather_pic');
-
36 }
-
37
-
38 function switchImage(place) {
-
39 if (place == "weather_pic") {
-
40 $('weather_pic').style.display = 'inline';
-
41 }
-
42 if (place == 'optical_pic') {
-
43 $('weather_pic').style.display = 'inline';
-
44 }
-
45
-
46 var new_image = getNextImage();
-
47 document[place].src = new_image;
-
48 var recur_call = "switchImage('"+place+"')";
-
49 timerID = setTimeout(recur_call, time_interval);
-
50 }
-
51
-
52 function cook(pictype) {
-
53 var type = pictype;
-
54 deleteCookie("pic_type");
-
55 setCookie("pic_type", type, 30);
-
56
-
57 choose_id();
-
58 }
-
-
60 function getNextImage() {
-
61 if (random_display) {
-
62 imageNum = randNum(0, totalImages-1);
-
63 } else {
-
64 imageNum = (imageNum+1) % totalImages;
-
65 }
-
66
-
67 var new_image = get_ImageItemLocation(imageArray[imageNum]);
-
68 return(new_image);
-
69 }
-
70 var totalImages = imageArray.length;
-
71
-
72 function imageItem(image_location) {
-
73 this.image_item = new Image();
-
74 this.image_item.src = image_location;
-
75 }
-
76
-
77 function get_ImageItemLocation(imageObj) {
-
78 return(imageObj.image_item.src)
-
79 }
-
80
-
81 function randNum(x, y) {
-
82 var range = y - x + 1;
-
83 return Math.floor(Math.random() * range) + x;
-
84 }
-
85
-
86
-
87 function getPrevImage() {
-
88 imageNum = (imageNum-1) % totalImages;
-
89 var new_image = get_ImageItemLocation(imageArray[imageNum]);
-
90 return(new_image);
-
91 }
-
92
-
93 function prevImage(place) {
-
94 var new_image = getPrevImage();
-
95 document[place].src = new_image;
-
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 -
<!-- Start right Column box -->
-
<div id="righcolbox">
-
<div>
-
<img height="385px" width="385px" align="right" id="weather_pic" border="3" src="img/revised/1.png" alt="Weather Images" />
-
<img height="385px" width="385px" align="right" id="optical_pic" border="3" src="img/Optical/1.png" alt="Optical Images" />
-
</div>
-
<!-- End right Column box -->
-
</div>
-
If you care to look at the site it is http://beta.climate.usurf.usu.edu
thanks again
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.
acoder 16,027
Recognized Expert Moderator MVP epots9 1,351
Recognized Expert Top Contributor
the variable place (that u use here: switchImage(pla ce)), what is it? what is it referencing?
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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.
|
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,...
|
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
| |
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
|
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...
|
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?
|
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)
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |