[hunchentoot-devel] Form Processing & responding to events

Mac Chan emailmac at gmail.com
Fri Mar 16 00:22:41 UTC 2007


> I noticed
> from the test demo for the easy handler example that hitting the enter key
> while on a text box will cause the form to be submitted but I can't see
> where in the code this is explicitly called for.

A lot of html objects (like <a> <input>, etc) have default action
associated with them.

So even if you bind a onclick handler to the <a href=...> tag to do
some interesting stuff, but unless your handler explicitly instructs
the browser to prevent the default action from taking place, it will
redirect to the href target after your handler is finished executing.

The enter key behavior that you described above also triggers a
browser default action (submitting the form), so if you don't want
that, you need to bind a custom handler and use it to prevent the
default behavior.

"Javascript the definitive guide" is a very good tutorial and
reference if you want to learn more about this.

> My question is that I can't
> find anything to indicate how I can capture something like an onClick or an
> onLoad event using the keyword notation provided by Hunchentoot.

I think you're referring to cl-who, not hunchentoot.

I'm not sure if this answers your question, but setting a onclick
handler for a tag is just a matter of assigning the corresponding
attribute.

(cl-who:with-html-output (out *standard-output*)
  (:a :href "target.html" :onclick "javascript:myFunc(); return false;"
      "Click Me"))

=>

<a href='target.html' onclick='javascript:myFunc(); return false;'>Click Me</a>

Of couse, you still need to define the javascript function myFunc(),
either by including a js file or embedding it in the cl-who form
(cl-interprol is of great help here) or even use the parentscript
library so you can write it in lisp too!

HTH,
-- Mac



More information about the Tbnl-devel mailing list