Toggle Image - Problem in IE

Discussion in 'Javascript' started by kiran, Jun 3, 2004.

  1. kiran

    kiran Guest

    Hi All

    I am using the below function to change an image. I have checked in IE
    and its working properly if seen locally on my system.

    If the same is inserted in a jsp file and accessed from server, image
    is toggled but it is not visible.

    If we right click on the image and select 'Show Picture' it is
    displayed.
    Weird IE problem!!!! Anyone has solutions for this.

    Kiran Makam


    function toggleImg(name){
    var obj = document.images[name];
    var src = obj.src.toLowerCase();

    if(src.indexOf("yes") != -1){
    obj.src = "images/no.gif";
    obj.alt = "Collapse";
    }else{
    obj.src = "images/yes.gif";
    obj.alt = "Expand";
    }
    }
    kiran, Jun 3, 2004
    #1
    1. Advertising

  2. Thats weird,

    I don't know why it goes wrong, but maybe preloading the images might
    help. In the header, put the following code:

    <SCRIPT LANGUAGE="JavaScript">
    imYes = new Image();
    imYes.src = 'images/yes.gif';
    imNo = new Image();
    imNo.src = 'images/no.gif';
    </SCRIPT>

    You're sure those images are the correct filenames? Did you check for
    upper & lowcase? might be sensetive to that.
    Vincent van Beveren, Jun 3, 2004
    #2
    1. Advertising

  3. kiran

    kiran Guest

    Thanks Beveren.

    I have preloaded the images, still the problem persists. I checked
    browser cache after the page is loaded, preloading is working fine.

    If i try the function in a static page on my system, it works; when it
    is added to a jsp file and accessed from server images refuses to show
    up!!!!!

    Kiran
    kiran, Jun 4, 2004
    #3
  4. > If i try the function in a static page on my system, it works; when it
    > is added to a jsp file and accessed from server images refuses to show
    > up!!!!!


    I have no idea. Sorry. It should indeed work.
    Vincent van Beveren, Jun 4, 2004
    #4
  5. kiran

    Grant Wagner Guest

    kiran wrote:

    > Thanks Beveren.
    >
    > I have preloaded the images, still the problem persists. I checked
    > browser cache after the page is loaded, preloading is working fine.
    >
    > If i try the function in a static page on my system, it works; when it
    > is added to a jsp file and accessed from server images refuses to show
    > up!!!!!
    >
    > Kiran


    Check the source the browser is seeing. It's most likely that when the JSP
    outputs the client-side JavaScript, you are losing quotation marks
    somewhere along the way.

    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

    * Internet Explorer DOM Reference available at:
    *
    http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-developer/upgrade_2.html
    Grant Wagner, Jun 4, 2004
    #5
    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. =?Utf-8?B?c2lhag==?=

    Image Toggle

    =?Utf-8?B?c2lhag==?=, May 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    482
    Steve C. Orr [MVP, MCSD]
    May 4, 2005
  2. Brian

    toggle image with onLoad event

    Brian, Mar 29, 2005, in forum: Javascript
    Replies:
    2
    Views:
    107
    Brian
    Mar 30, 2005
  3. Madame Blablavatsky

    how to toggle images when one clicks a image/ link

    Madame Blablavatsky, Sep 5, 2005, in forum: Javascript
    Replies:
    2
    Views:
    92
    Evertjan.
    Sep 5, 2005
  4. ameshkin
    Replies:
    4
    Views:
    150
    Dr J R Stockton
    Jul 22, 2008
  5. neetu
    Replies:
    1
    Views:
    218
Loading...

Share This Page