> This generates "element has no properties" in prototype.js in
> line 1479
> 
> <script type="text/javascript">
> 
>     function sayHello() {
>         alert( 'Hello Message' );
>     }
> 
>     Event.observe( 'updater1', 'click', sayHello, false);
> 
> </script>
> 
> And the element with that id is:
> 
> <a href="http://localhost:3000/workshop/classes?o=name&amp;p=7";
> id="updater1">Workshop</a>

Is the element farther down the page than the javascript?  HTML is
rendered in the order it is output.  If you try to get an element that
has yet to be rendered, it does not exist.

> The problem with prototype and all these nice javascript libraries is
> that it makes it easy for someone like me to use them. ;)

Not to knock you too hard, but yeah, it is.  Then again, we all were
newbies at some point, so if it came out 5 years earlier, I'd be the one
asking the questions.  I actually shyed away from javascript for a
couple years until Prototype and Scriptaculous came out and made it fun
again.

> I didn't realize that the inline handlers were any different than what
> you have above.  I thought they all assigned to the same event.

Well, it's in how browsers deal with them.  Library functions like
Event.stop() deal with the browser inconsistencies internally, so you
don't have to worry about them.  Event handling has always been one of
the major differences in browsers.  Standards-based browsers pass the
event object to the event handling function (hence the function (e)
{...}, where e is the event object), IE stores the last-fired event in
window.event.  IE and Mozilla have different ways of attaching events in
javascript, as well (IE = element.onclick = function, Mozilla =
element.addEventListener('click', function)).  It gets even worse when
trying to determine where the mouse was when the event fired and what
element fired the event.  Just use the prototype functions and all will
be well, but remember to have the javascript that attaches the events be
called AFTER the element has been rendered.

Did you get all that?

Greg
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to