Intercept Form Submit

167 views
Skip to first unread message

Hector

unread,
Jul 27, 2007, 11:45:35 AM7/27/07
to MochiKit
What is the most efficient way to intercept a form submit event?
"onsubmit" in the form tag? "onclick" on the submit button? Make use
of the connect function? Something else? Additionally, I would
prefer that this method fail in a way that allowed for a normal submit
to occur if JavaScript were disabled.

Karl Guertin

unread,
Jul 27, 2007, 12:45:38 PM7/27/07
to Hector, MochiKit

connect(formElement,'onsubmit',function(e){
console.log(e); //see what's in the Signal event if you don't know
return false; //prevent form submission
});

Chris Winters

unread,
Jul 27, 2007, 2:00:09 PM7/27/07
to gray...@gr.ayre.st, Hector, MochiKit
Will returning false prevent form submission? I thought you needed to do:

function (e) {
// .. do your activities

// prevent the event from propogating
e.stop();
}

Chris

Karl Guertin

unread,
Jul 27, 2007, 2:23:44 PM7/27/07
to Chris Winters, MochiKit
On 7/27/07, Chris Winters <chris....@gmail.com> wrote:
> Will returning false prevent form submission?

To my knowledge, returning false works in all browsers. I believe that
e.stop() will do the same thing. It's been a while since I've had to
do this so I figured I'd put in what I know to work.

Hector

unread,
Jul 27, 2007, 6:02:39 PM7/27/07
to MochiKit
I've only ever used return false with onsubmit in the form tag.

On Jul 27, 2:23 pm, "Karl Guertin" <grayr...@gmail.com> wrote:

Beau Hartshorne

unread,
Aug 3, 2007, 3:13:10 PM8/3/07
to gray...@gr.ayre.st, Hector, MochiKit

return false; doesn't do anything here, this should look like:

connect(formElement,'onsubmit',function(e){
console.log(e); // see what's in the Signal event if you don't know
e.stop(); // prevent form submission
});

Beau

Reply all
Reply to author
Forward
0 new messages