Re: IE can't access image src



On Dec 28, 7:51 pm, faraz_mit <Faraz...@xxxxxxxxx> wrote:
Hi
I posted the same issue but since I was using the old syntax of
"document.all", I took the focus away from the actual problem. I  am
trying to change the image source on a click event but can't access
the image src using Internet explorer. Same code works fine in Firefox
and alerts the correct image src but I get undefined in Internet
explorer. I am using IE version 6.

I also tried document.images['im'], document.getElementById['im'], and

That second one is nonsense. Use:

document.getElementById('im')

(presuming that the image element has an ID of "im.")

document['images']['im'] but none of them worked.

That is the same as document.images['im'] or document.images.im, which
will retrieve the image if it has that name. IIRC, in some browsers,
it will retrieve an image with an ID of 'im', but only if there is no
contradictory name attribute.


Here is the code I have:

/* in the head section I have the following simple javascript function
*/
function changeimgsrc(img_src) {
         alert(document.getElementById('im').src);
         document.getElementById('im').src = img_src;


Since you used an ID attribute and no name, this would be your best
bet.

}

/* in the body section I have the following nested div structure */
<div id="horizontal_container" >
 <h3 class="horizontal_accordion_toggle">...</h3>
        <div id="m1" class="horizontal_accordion_content">
                <div  id="m2" ><img id="im"  width="360"  src="images/
com_01_angle.gif"   /></div>

It isn't the cause of the problem, but get rid of that slash at the
end of the img tag (unless you plan to serve this as XHTML.)

                ....
               <div ><a href="#"
onclick="changeimgsrc('cum_01_angel_blue.gif');">test</a> </div>
                 ......


Do you have an element with a name attribute of "im" elsewhere on the
page? IE will retrieve elements by name with getElementById.
.



Relevant Pages

  • Re: IE cant access image src
    ... the image src using Internet explorer. ... Same code works fine in Firefox ... and alerts the correct image src but I get undefined in Internet ... /* in the head section I have the following simple javascript function ...
    (comp.lang.javascript)
  • IE cant access image src
    ... I posted the same issue but since I was using the old syntax of ... the image src using Internet explorer. ... and alerts the correct image src but I get undefined in Internet ... /* in the head section I have the following simple javascript function ...
    (comp.lang.javascript)
  • Re: IE cant access image src
    ... the image src using Internet explorer. ... and alerts the correct image src but I get undefined in Internet ... /* in the head section I have the following simple javascript function ... If you absolutely insist on using the onclick event of a link, ...
    (comp.lang.javascript)
  • Re: How to retrieve files after emptying the recycle bin?
    ... I just want to retrieve a lost image file... ... when i use "internet explorer" to "set background", ... as you set background using internet explorer. ...
    (microsoft.public.windowsxp.general)
  • Drop a file in Internet Explorer
    ... retrieve the file path. ... I know it's not possible with Internet Explorer ... someone have some example or source code of a non-visible ActiveX wich ... can retrieve the path of the dropped file, it will be marvellous for me ...
    (microsoft.public.scripting.jscript)