[Javascript] Stopping default action
Bill Moseley
moseley at hank.org
Fri Mar 31 09:56:14 CST 2006
On Fri, Mar 31, 2006 at 08:06:32AM -0500, Mike Dougherty wrote:
> If you are building a Ajax as a workaround for inline clicks then you are
> working way too hard...
Yes, I'm trying to fix something that isn't broken.
> you can deliver semantic markup without the clutter of javascript function
> registration and an external script that attaches events to the controls
> without using ajax. I'm not sure what you meant by "...get rid of my
> inline onclicks"
No, I'm not using ajax to to register the events. By "get rid of my
inline onclicks" simply means removing the onclick from my <a
href=..."> tags and apply with something like Event.Observe().
I've got a <div> that is updated by an ajax request, say clicking on a
table heading sorts by that column, or selecting a tab as in the
example below). The links (with the onclick behavior) are included
*within* the <div>.
If the onclick is in-lined into those links returned in the ajax
response, then all is well; they get set when the response is
processed by the browser. Here's an example of that method:
http://hank.org/demos/ajax-inline.html
Now, since I'm trying to get rid of the in-line onclick on my <a>
elements, I need a way to re-assign the event handlers to the <a>
elements after the ajax update.
What I'm doing now is including a <script> section in the ajax update
http://hank.org/demos/ajax.html
and telling Prototype's Ajax.Updater to run any <script> sections
returned in the ajax response, as you can see in this response:
http://hank.org/demos/recent
I posted about this earlier on the Rails spinoff list (which sometimes
discusses Prototype). Sorry for any duplicates.
--
Bill Moseley
moseley at hank.org
More information about the Javascript
mailing list