473,396 Members | 1,843 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,396 software developers and data experts.

Javascript Working With IE But Not Netscape

Can anyone explain why the following script works in IE but not
Netscape?

function changeSlide() {
if (form1.pic1.src.indexOf("diane.jpg") != -1) {
form1.pic1.src = "http://home.comcast.net/~llabbauf/public_html/graphics/tdub.gif";
} else if (form1.pic1.src.indexOf("tdub.gif") != -1) {
form1.pic1.src = "http://home.comcast.net/~llabbauf/public_html/graphics/thug.jpg";
} else if (form1.pic1.src.indexOf("thug.jpg") != -1) {
form1.pic1.src = "http://home.comcast.net/~llabbauf/public_html/graphics/diane.jpg";
}
}

function runSlideShow() {
setInterval("changeSlide()", 1000);
}
</script>

<form name="form1">
<img src="http://home.comcast.net/~llabbauf/public_html/graphics/diane.jpg"
name="pic1">
</form>

When viewed in IE it accurately changes the images, but Netscape just
loads the first image and then does nothing.

Les
Jul 20 '05 #1
3 1260
ll******@state.pa.us (evil_bastard) writes:
Can anyone explain why the following script works in IE but not
Netscape?
Yes. (Ok, can I stop here? :)
function changeSlide() {
if (form1.pic1.src.indexOf("diane.jpg") != -1) {


You have not declared the variable "form1".
IE automatically declares global variables for named elements, other
browsers doesn't.

Use
var form1 = document.forms['form1'];

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
evil_bastard wrote:
Can anyone explain why the following script works in
IE but not Netscape?

function changeSlide() {
if (form1.pic1.src.indexOf("diane.jpg") != -1) {

<snip>

There is no reason to expect "form1" to be a global variable (property
of the global object) that refers to the FORM element or for the IMG
element with the name "pic1" to be a named property of that form object.
On IE they are but other browsers do not provide nearly as many
shortcuts as IE does so all of the IE shortcuts are best avoided for
cross-browser work.

Richard.
Jul 20 '05 #3

Thanks for the reply. The coworker who provided me with the script
language in the first place just helped me debug it and we came to the
same conclusion.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Binny V A | last post by:
Hello Everyone, I am writing an tutorial(http://www.geocities.com/binnyva/code/javascript/basic_tutorial/index.html) for JavaScript and I wanted to include the link of the Netscape's official...
10
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...

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.