Javascript Working With IE But Not Netscape

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • evil_bastard

    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.ne t/~llabbauf/public_html/graphics/tdub.gif";
    } else if (form1.pic1.src .indexOf("tdub. gif") != -1) {
    form1.pic1.src = "http://home.comcast.ne t/~llabbauf/public_html/graphics/thug.jpg";
    } else if (form1.pic1.src .indexOf("thug. jpg") != -1) {
    form1.pic1.src = "http://home.comcast.ne t/~llabbauf/public_html/graphics/diane.jpg";
    }
    }

    function runSlideShow() {
    setInterval("ch angeSlide()", 1000);
    }


    </script>

    <form name="form1">
    <img src="http://home.comcast.ne t/~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
  • Lasse Reichstein Nielsen

    #2
    Re: Javascript Working With IE But Not Netscape

    llabbauf@state. pa.us (evil_bastard) writes:
    [color=blue]
    > Can anyone explain why the following script works in IE but not
    > Netscape?[/color]

    Yes. (Ok, can I stop here? :)
    [color=blue]
    > function changeSlide() {
    > if (form1.pic1.src .indexOf("diane .jpg") != -1) {[/color]

    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 - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Richard Cornford

      #3
      Re: Javascript Working With IE But Not Netscape

      evil_bastard wrote:[color=blue]
      > Can anyone explain why the following script works in
      > IE but not Netscape?
      >
      > function changeSlide() {
      > if (form1.pic1.src .indexOf("diane .jpg") != -1) {[/color]
      <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.


      Comment

      • Les Labbauf

        #4
        Re: Javascript Working With IE But Not Netscape


        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!

        Comment

        Working...