I've created a custom tooltip function to be used on a website. I'm
trying to code it in such a way that by giving any img tag an
attribute with tooltip="productid" it will attach the correct
onmouseover and onmouseout event.

Here is the code:

loadEvents: function() {
                var images = document.getElementsByTagName("img");
                var myElement = null;
                var myProductID = 0;
                for (var i = 0; i < images.length; i++) {
                        myElement = images[i];
                        if (myElement.hasAttribute("tooltip")) {
                                myProductID = myElement.getAttribute("tooltip");
                                Event.observe(myElement, 'mouseover', function()
{ productTooltip.show(myProductID,myElement); });
                                Event.observe(myElement, 'mouseout', function()
{ productTooltip.hide(); });
                        }
                }
        }

What this is doing is looping through all the imgs on the page and
finding any of the ones that have the tooltip attribute, then usinv
Event.observe to attach the onmouseover and onmouseout events. But the
problem is with the onmouseover I need to pass it two arguments, the
product ID which I get from the tooltip attribute and then I need to
pass it a reference to that particular element so my show() function
knows how to position the tooltip.

After this function is run, it correctly attaches an onmouseover and
onmouseout event to all of the neccessary images that have the tooltip
attribute, except it passes the product ID and element reference of
the last tooltip image that was processed. So if I had 3 tooltip
images on the page, all 3 mouseovers will run the show() function
using the third images ID and element reference.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to