470,599 Members | 1,529 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,599 developers. It's quick & easy.

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 1207
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 discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.