Hi,

On IE, Prototype can't extend elements at the prototype level and so
you have to extend them individually if you get/create them without
going through Prototype. To do that, just pass the element through the
`$` function:

var newImg = $(document.createElement("img"));

The reason you don't have to do that on Firefox or other browsers is
that on those browsers, Prototype can add its enhancements to the
*prototypes* of elements rather than individually to each element. But
not on IE. More here:
http://prototypejs.org/learn/extensions

You have to do this whenever you use raw DOM methods (like
document.createElement, or document.getElementById, or
document.getElementsByTagName, etc.) rather than Prototype
equivalents.

Alternately, of course, you can just go through Prototype whenever
creating or retrieving elements; then Prototype will ensure they've
been extended before giving them to you. E.g.:

function addImage(src, div) {
        var newImg = new Element("img");
        newImg.id="Image"+div;
        $("img"+div).appendChild(newImg);
        papa=$("img-upload");
        $("img"+div).style.display="block";
        hijo=$("upload"+div).style.display="none";
        newImg.src = src;
        newImg.observe('load', loadcrop);
}

There I've just replaced `document.createElement` with `new Element`
and replaced `document.getElementById` with `$`.

Separately, I would recommend reversing the order of your last two
lines to:

        newImg.observe('load', loadcrop);
        newImg.src = src;

...just in case the image is already in cache.

HTH,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Jun 28, 4:06 pm, edwingt <edwin.al...@gmail.com> wrote:
> Hello I'm trying to do an event observe work on IE, it works good on
> FF and Chrome, this is the script. When the newImg.observe() is
> reached I catch an exception with this msg "'src' is undefined"
>
> function addImage(src, div) {
>         var newImg = document.createElement("img");
>         newImg.id="Image"+div;
>
>         document.getElementById("img"+div).appendChild(newImg);
>         papa=document.getElementById("img-upload");
>         document.getElementById("img"+div).style.display="block";
>         hijo=document.getElementById("upload"+div).style.display="none";
>
>         newImg.src = src;
>          newImg.observe('load', loadcrop);
>
> }
>
> function loadcrop(evt)
> {
>
>         img = evt.findElement();
>         var txt = new String(img.id);
>         addCrop(txt.slice(5,6));
>
> }
>
> Thanks if you can help me solve this problem.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to