document.getElementById.src not working in ie!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Linto81
    New Member
    • Jun 2008
    • 7

    document.getElementById.src not working in ie!

    Please help... this is doing my head in! I have some gifs within a page that when clicked on switch to an animated version. The script below works great in FF or safari... but not in ie. Any tips here would save me hitting the bottle!

    the img tag is:

    [HTML]<img src="/graphics/prmoff.gif" width="250" height="188" id="prm" onClick="animat eMe('prm');" alt="Click to start/stop animation">
    [/HTML]
    the code is:

    [CODE=javascript]function animateMe(id){

    var onsrc = /graphics/" + id + "on.gif";
    var offsrc = /graphics/" + id + "off.gif";
    var newSrc = document.getEle mentById(id).sr c;
    alert(newSrc);
    var pos=newSrc.inde xOf('on.gif');

    if(pos=="-1"){
    document.getEle mentById(id).sr c=onsrc;
    }
    else {
    document.getEle mentById(id).sr c=offsrc;
    }
    }[/CODE]
    Last edited by acoder; Aug 18 '08, 10:20 AM. Reason: Added [code] tags
  • vee10
    New Member
    • Oct 2006
    • 141

    #2
    Hi,

    Its working fine for me in the IE also .
    Whats the error u r getting while executing in the IE .

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Have you got any element named "prm" in the page?

      Comment

      • vee10
        New Member
        • Oct 2006
        • 141

        #4
        hi,

        Yes i got the element since she passed it as an argument and it is the id of the image
        Code:
        <img src="set1.jpg" width="250" height="188" id="[B]prm[/B]" onClick="animateMe('prm');" alt="Click to start/stop animation">
        Originally posted by acoder
        Have you got any element named "prm" in the page?

        Comment

        • Linto81
          New Member
          • Jun 2008
          • 7

          #5
          Sorry Vee ...

          Are you saying it 'is' or 'isn't' working in ie for you?

          If FF etc, with the alert in place I get the SRC of the img I need ot play with. In ie I get 'Undefined'

          Any help?

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by vee10
            Yes i got the element since she passed it as an argument and it is the id of the image
            Code:
            <img src="set1.jpg" width="250" height="188" id="[B]prm[/B]" onClick="animateMe('prm');" alt="Click to start/stop animation">
            Sorry, I should've quoted. I was referring to the OP.

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by Linto81
              If FF etc, with the alert in place I get the SRC of the img I need ot play with. In ie I get 'Undefined'
              From the code you've posted, it should work. Do you have any other elements on the page with name or ID "prm"? If not, can you post the rest of the code (if not too much).

              Comment

              • Linto81
                New Member
                • Jun 2008
                • 7

                #8
                There is a shed load of code as it sits within an included js file with many finctions in it.

                I expect that there is a conflict somewhere in there... its just finding the bugger!

                I am surprised though that FF works when ie doesn't - its normally the other way around!!

                Thanks for your help guys... Back to the code search now :(

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by Linto81
                  I am surprised though that FF works when ie doesn't - its normally the other way around!!
                  If that's the case, then there must be something wrong with the way you normally code. You'll find that most programmers/developers test or, at least should test, in a more standards-compliant browser (Firefox, Opera, etc.) then test in IE.

                  Comment

                  Working...