Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Some JS works with IE and Opera but not Mozilla! 3

Status
Not open for further replies.

iXPhound

Technical User
Feb 25, 2001
146
US
Hi all,

Hope someone can help a newb to web development.

I am using a table and have a field
<td colspan="13">
<a href="#"
onclick="changeBanner();">
<img name="Banner" src="images/Banner0.gif" width="658"height="102" border="0" alt=""/>
</a>
</td>

The changeBanner function is simply:

var i = 0;
function changeBanner()
{
if (i >= 0 && i < 7)
{
i+=1;
Banner.src = "images/Banner" + i + ".gif";
}
else
{
i=0;
Banner.src = "images/Banner" + i + ".gif";
}
}

This is probably a bad way of doing things (not really sure because I am still learning) but it works fine in IE and Opera but will not work in Mozilla FireFox 1.0 or Mozilla 1.75.

Any suggestions are greatly appreciated.

TIA!!!!
 
try this.

Add an ID to the IMG
<img name="Banner" src="images/Banner0.gif" width="658"height="102" border="0" alt=""/ id="Banner">


then change the source like this

function changeBanner()
{
theBanner = document.getElementById("Banner")
if (i >= 0 && i < 7)
{
i+=1;
theBanner.src = "images/Banner" + i + ".gif";
}
else
{
i=0;
theBanner.src = "images/Banner" + i + ".gif";
}
}


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Code:
<html>
<head>
<script type="text/javascript">
<!--

var i = 0;
function changeBanner()
{
  [red]var banner = document.getElementById("banner");[/red]
  if (i == 7)
    i = 0;
  banner.src = "images/Banner" + i + ".gif";
  i++;
}

// -->
</script>
</head>
<body>
<a href="#" onclick="changeBanner(); return false;">
 <img src="banner0.gif" id="banner" name="banner">
</a>
</body>
</html>

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Thanks for the suggestion guys.
Unfortunately I am having the same problem. Both ideas work in IE and Opera but still not changing the banners in Mozilla or Firefox. Any other suggestions would be hugely appreciated!!!

TIA!
 
While this is not a direct answer to your question, here's an archive file I have that is tried and tested. It rotates every five seconds, but you should be able to use the logic here for your own page.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]

<html>
<head>
<title>new document</title>

<script language="javascript" type="text/javascript">
<!--

var cur_image = 0;
var img_array = new Array("[URL unfurl="true"]http://www.google.com/images/logo.gif",[/URL] "[URL unfurl="true"]http://us.a1.yimg.com/us.yimg.com/i/ww/beta/y3.gif",[/URL] "[URL unfurl="true"]http://www.ibm.com/i/v14/t/ibm-logo.gif");[/URL]
var href_array = new Array("[URL unfurl="true"]http://www.google.com/",[/URL] "[URL unfurl="true"]http://www.yahoo.com/",[/URL] "[URL unfurl="true"]http://www.ibm.com");[/URL]

function loadImg() {
    if (cur_image == img_array.length) cur_image = 0;
    document.getElementById('banner').src = img_array[cur_image];
    document.getElementById('banner_href').href = href_array[cur_image];
    cur_image++;
    setTimeout('loadImg()', 5000);
}

-->
</script>

</head>

<body onload="setTimeout('loadImg()', 5000);">
    <div id="header">
        <a href="[URL unfurl="true"]http://www.google.com/"[/URL] id="banner_href" target="_blank">

            <img id="banner" src="[URL unfurl="true"]http://www.google.com/images/logo.gif"[/URL] />
        </a>
    </div>
    <div id="main">
        This is a banner rotator script.  Every 5 seconds (5000 milliseconds according to JavaScript, the next image in the array will load.  Once it gets to the last image, it will start from the beginning.
    </div>
</body>

</html>

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
My code works perfectly in my FireFox... is there anything else on the page?

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
chess, congrats on TOTW :)

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
Why, thank you.

And I have no idea how, as I have been away the last two days... but I suppose that gets filed away as "unexplicable" with the MVP selection.

Sigh.

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
nothing is explainable on this site. I think they pick the top ten people, then use a random number generator to determine the order.

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
Makes as much sense as any other way...

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
You mean this one?

cLFlaVA, just noticed that you posted another solution...
I think I've seen that particular snippet about three or four times... maybe people should use the search feature (or is it down again?)

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Dunno, too lazy to click the button. I'd rather type. Yeah, I plaster that badboy everywhere, it seems to be a popular request.

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
I appreciate the help but I am having no sucess with this in Mozilla. One thing I did notice was that in the status bar for my page it says Waiting for "the server"... even ~30 minutes after the page seems to load. Does this suggest a problem somewhere else in the page?

Thank you again for all of your help!
 
My apologies guys...the problem was case. I had the element ID starting with an uppercase. Again, I am sorry! Everything is working fine in all browsers now.

Thank you all for all of your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top