Event.observe doesn't work

0 views
Skip to first unread message

cgusupport

unread,
Sep 28, 2007, 6:18:50 PM9/28/07
to Ruby on Rails: Spinoffs
Hi,

The following simple html doesn't work with errors, why?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/
html4/strict.dtd">
<html>
<title>click</title> <head>
<h2>Click!</h2>
<script type="text/javascript" language="javascript">
Event.observe('myAnchor', 'click', function(e){ alert('clicked
me!') });
</script>
<a href="#null" id="myAnchor">1</a>
</body>
</html>


Error: Event not define.

Frank Schummertz

unread,
Sep 29, 2007, 3:00:38 AM9/29/07
to rubyonrail...@googlegroups.com
cgusupport schrieb:

> The following simple html doesn't work with errors, why?

You should load prototype.js if you want to use it ;-)

<script type="text/javascript" src="path/to/prototype.js"></script>

Frank


--
"Laut einer Studie der deutschen Ärztevereinigung sterben immer
mehr Rentner vor dem Computer. Sie drücken versehentlich die
Tastenkombination Alt+Entfernen."

http://www.landseer-stuttgart.de
http://www.pn-cms.de

redheat

unread,
Sep 29, 2007, 6:50:43 AM9/29/07
to Ruby on Rails: Spinoffs
1: you need to include prototype.js
2: you should always define observers after the element is written in
your code, i.e., *after* <a ... id="myAnchor">. To do this, either add
your functions at the bottom of the page, or Event.observe(body,
'load', function() { <FUNCTIONS> }); and add the functions in here.

Edd

Reply all
Reply to author
Forward
0 new messages