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
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 -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<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="switchDiv('weather_pic')"> Weather Pictures</span> :
-
<span onclick="switchDiv('optical_pic')"> 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>
-
could someone help with this?
11 2095
Heya, BD.
It looks like this is the line that is causing you grief (in switchImage()): -
document[place].src = new_image;
-
Try this: -
var img = document.getElementsByName(place)[0];
-
if(img)
-
{
-
img.src = new_image;
-
}
-
else
-
{
-
// Debug
-
alert(place);
-
}
-
I think you are on to something, but I am still having trouble
this is what I changed the function to -
function switchImage(place) {
-
var new_image = getNextImage();
-
var img = document.getElementByName(place)[0];
-
if (img) {
-
img.src = new_image;
-
} else {
-
//debug
-
alert(place);
-
}
-
//document[place].src = new_image;
-
var recur_call = "switchImage('"+place+"')";
-
timerID = setTimeout(recur_call, interval);
-
}
-
IE error
Object doesn't support this property or method
line 95 char4
what am i doing wrong?
It no longer works in Mozilla as it did before I receive the error
document.getElementByName is not a function.
Ok fixed my one problem it is getElementsByName not getElementByName
I'm not receiving an error in IE but my images never appear. In Mozilla I just receive the error message every 5 seconds.
Does anyone know how to fix this.
Thanks
well im not an expert on this so i might be wrong
but this lines look weird to me -
// those quotation marks look weird to me
-
// iam not sure about the purpose of it...
-
//wouldnt you have to use eval(recure_call) after that?
-
// pbmods probably knows
-
var recur_call = "switchImage('"+place+"')";
-
-
timerID = setTimeout(recur_call, interval);
-
-
//anyway i would try to write them :
-
-
var recur_call = place;
-
timerID = setTimeout(switchImage(recur_call), interval);
-
}
-
i hope that helped
jx2
Heya, JX2.
In this code: -
var recur_call = "switchImage('"+place+"')";
-
recur_call might, for example, evaluate to:
switchImage('id_weather');
However, you can also do this: -
timerID = setTimeout(function() { switchImage(place); }, interval);
-
Now that I'm looking at it, you actually want to do this instead: -
var img = document.getElementById(place);
-
if(img)
-
{
-
img.src = new_image;
-
}
-
else
-
{
-
// Debug
-
alert(place);
-
}
-
The document[place] syntax confused me because long-time IE programmers often get element names and IDs confused (since IE makes them more or less equivalent; this is incidentally why a lot of IE designers abuse IDs).
Heya, JX2.
In this code: -
var recur_call = "switchImage('"+place+"')";
-
recur_call might, for example, evaluate to:
switchImage('id_weather');
However, you can also do this: -
timerID = setTimeout(function() { switchImage(place); }, interval);
-
thx a lot pbmods - nice trick
- i learn a lot from you!!
hough!!
Ok I believe I got it. Thanks again for all the help.
I had one div/id working and couldn't get the other one to work.
After a long step by step walk through the problem was that one of img sets couldn't be displayed for some reason. They were .png images. I made them .jpg images and it worked. I don't understand why .png doesn't work but that was the problem.
Do either of you know why?
Anyways here is all my code if you ever have to do the same thing.
check out the site:
http://beta.climate.usurf.usu.usu.edu -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<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="switchDiv('weather_pic')"> Weather Pictures</span> :
-
<span onclick="switchDiv('optical_pic')"> 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>
-
thanks again
Heya, BD.
Just a guess, but maybe this had something to do with it... -
imageArray[imageNum++] = new imageItem(image_dir + i + "-->.jpg<--");
-
:P
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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>
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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;
|
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,,,
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |