Firefox/ie issue with img src update?

Discussion in 'Javascript' started by David Housman, Jan 24, 2007.

  1. Hello,

    Though this came up in the act of learning js, I'm not actually sure
    this is a js question. I can write and call a function to update the
    src of an image. But in Firefox the image quickly reverts back to the
    original one. In IE it seems to work properly.
    I boiled this down to the following lines:

    <img name = "myImage" src = "script/images/balloon.gif" width="106"
    height="131">
    <a href
    onClick="document.myImage.src='script/images/heron.gif'"))>heron!</a>

    If this isn't a js question, I'd appreciate it someone could point me
    in the right direction. Thanks in advance for your understanding and
    assistance.

    Thanks again,
    Dave
     
    David Housman, Jan 24, 2007
    #1
    1. Advertising

  2. David  Housman

    -Lost Guest

    "David Housman" <> wrote in message
    news:...
    > Hello,
    >
    > Though this came up in the act of learning js, I'm not actually sure
    > this is a js question. I can write and call a function to update the
    > src of an image. But in Firefox the image quickly reverts back to the
    > original one. In IE it seems to work properly.
    > I boiled this down to the following lines:
    >
    > <img name = "myImage" src = "script/images/balloon.gif" width="106"
    > height="131">
    > <a href
    > onClick="document.myImage.src='script/images/heron.gif'"))>heron!</a>
    >
    > If this isn't a js question, I'd appreciate it someone could point me
    > in the right direction. Thanks in advance for your understanding and
    > assistance.
    >
    > Thanks again,
    > Dave


    Hrmm... no clue if this is the culprit, but why is there 2 parenthesis after the event
    handler?

    <a href="heron.htm" onclick="document.myImage.src='script/images/heron.gif'; return
    false;">heron!</a>

    -Lost
     
    -Lost, Jan 24, 2007
    #2
    1. Advertising

  3. David  Housman

    Randy Webb Guest

    -Lost said the following on 1/24/2007 1:14 AM:
    > "David Housman" <> wrote in message
    > news:...
    >> Hello,
    >>
    >> Though this came up in the act of learning js, I'm not actually sure
    >> this is a js question. I can write and call a function to update the
    >> src of an image. But in Firefox the image quickly reverts back to the
    >> original one. In IE it seems to work properly.
    >> I boiled this down to the following lines:
    >>
    >> <img name = "myImage" src = "script/images/balloon.gif" width="106"
    >> height="131">
    >> <a href
    >> onClick="document.myImage.src='script/images/heron.gif'"))>heron!</a>
    >>
    >> If this isn't a js question, I'd appreciate it someone could point me
    >> in the right direction. Thanks in advance for your understanding and
    >> assistance.
    >>
    >> Thanks again,
    >> Dave

    >
    > Hrmm... no clue if this is the culprit, but why is there 2 parenthesis after the event
    > handler?
    >
    > <a href="heron.htm" onclick="document.myImage.src='script/images/heron.gif'; return
    > false;">heron!</a>


    The issue was with the lack of a return false in the event handler. The
    onclick fires, the image gets changed, the href gets followed and
    Firefox is reloading the page so that it goes back to the original image.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Jan 24, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Richter

    <txt src= ...> equivalent of <img src= ...>

    Steve Richter, Feb 8, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    2,098
    Laurent Bugnion
    Feb 9, 2006
  2. Greg Johnson
    Replies:
    4
    Views:
    3,080
  3. Replies:
    1
    Views:
    1,624
    Alex Hunsley
    Mar 23, 2007
  4. pheadxdll
    Replies:
    16
    Views:
    3,687
    Neredbojias
    Jun 6, 2007
  5. Soren Vejrum
    Replies:
    4
    Views:
    616
    Lasse Reichstein Nielsen
    Jul 5, 2003
Loading...

Share This Page