How do you stop a dynamically loaded form from submitting with jquery?

Posted by Zak on Stack Overflow See other posts from Stack Overflow or by Zak
Published on 2011-02-26T15:17:40Z Indexed on 2011/02/26 15:24 UTC
Read the original article Hit count: 179

Filed under:
|

I'm working on an AJAX login system. Right now, when the user clicks on a link, the login form is dynamically loaded when the person clicks on a "log in" link. Since I'm using AJAX for this, I want to prevent the form from actually submitting when the submit button is clicked. I tried the following code as part of my load function, and the form loads correctely, but the form still submits normally.

$('#loginBox').load('loginform.php');
$('#loginBox form').submit(function(event) {
 event.preventDefault();
});

How can I fix this?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery