Forum: Rails Spinoffs (closed, excessive spam) Ajax.Updater cannot submit through "return" key

D0f27fd7e737f89d380a81113920008c?d=identicon&s=25 Chris (Guest)
on 2008-06-13 06:34
(Received via mailing list)
This may be a really simple problem, my ajax.request only works if I
click the button that has the onclick="Ajax.Updater Function".
Whenever I try to submit the form using the return key it processes it
as a non-ajax request.  Is there anyway that I can submit my form by
both clicking on the button and hitting the "return" key?
Thank you!
Af85e01e19b6caa679621b7b783a598f?d=identicon&s=25 T.J. Crowder (Guest)
on 2008-06-13 09:23
(Received via mailing list)
Hey Chris,

Can you give us a bit more to go on?  Maybe post a minimal test case
to  Tell us what browsers you're seeing this on and
what browsers you plan to support?

My first reaction, without knowing the above, is that onclick is a
mouse event and so it's not a surprise that the keyboard equivalent
doesn't go through it (it's disappointing, but not _surprising_).  If
this is a form and the button in question is a submit button, I'd tend
to think using the "onsubmit" of the form instead would solve the
problem (just be sure to return false so it doesn't get submitted
twice).  Otherwise, there are ways to hook keyboard events and do
this, but it's more hassle.

T.J. Crowder
tj / crowder software / com
D0f27fd7e737f89d380a81113920008c?d=identicon&s=25 Chris (Guest)
on 2008-06-14 03:14
(Received via mailing list)
Hi TJ,
Here is a link to simple prototype todo list app
It works fine if you click the "Add" button but when trying to submit
the form with the return key it treats it like a normal form submit.
I did try the onsubmit and had no luck.
F3cf74d456662cf50cafa74433a83e5b?d=identicon&s=25 Brian Williams (Guest)
on 2008-06-14 04:52
(Received via mailing list)
move the onclick code back to onsubmit and change the button to input
D0f27fd7e737f89d380a81113920008c?d=identicon&s=25 Chris (Guest)
on 2008-06-14 07:05
(Received via mailing list)
Hi Brian,
I gave that a try, didn't seem to work.  Thanks for the suggestion,
any other thoughts?

9d1fd4918c75d02c7904643f0fe12f31?d=identicon&s=25 Anders Bjarby (Guest)
on 2008-06-14 08:42
(Received via mailing list)
Also, make sure that the onsubmit action returns a false so that the
actual form action is not called for.


14 jun 2008 kl. 04.51 skrev Brian Williams:
Af85e01e19b6caa679621b7b783a598f?d=identicon&s=25 T.J. Crowder (Guest)
on 2008-06-14 09:26
(Received via mailing list)
Hi Chris,

> I did try the onsubmit and had no luck.

Again, specifics are useful -- no luck *how*?

It works fine for me on FF2, IE6, Op9, and Safari3 on Windows XP:

This example just shows the result of the post in a div via
Ajax.Updater, but you can use Ajax.Request if it's more appropriate to
your needs.  The JSP used in this example just writes out "<p>You sent

Items of note:

* Give the form an ID to make it easy to retrieve via $().
* Hook up the event via Element.observe().
* Stop the event in the submit handler via evt.stop().

Hope this helps,
T.J. Crowder
tj / crowder software / com
This topic is locked and can not be replied to.