mowgli mowgli - 1 year ago 61
Javascript Question

Submit a form generated by jquery

The login form on my site is shown using an overlay/modal with jquery-modal (

I'm using ajax + php to validate the form. If validation passes, the form should be submitted.

I can halt the submit for validation (using return false), and the validation itself is working fine. But I don't know how to submit the form

I have tried many naive variations: return true, $theform.submit(), $("body").unbind("#myloginform") and more.. but so far no luck

$("body").on("submit", "#myloginform", function() {

$theform = $(this);

url: "login_check.php",
type: "POST",
cache: false,
timeout: 9000,
data: $theform.serialize(),
dataType: "json",
success: function(data) {
if (data) {
if (data.status == "ok") {
alert("success! now the form can be submitted");
// SUBMIT THE FORM (instead of the alert)
} else {
$("body #loginstatus").html(data.status);
} else {
alert("Error bla bla.");
error: function(e) {
alert("Error (ajax) bla bla.");

return false;


Answer Source

To submit the FORM, you can call js native submit method:


See variants:


An other way would be to set context option of ajax to this:

     context: this,

And then in success callback, submit FORM using:


EDIT: i see you are already using a variable reference, so in your case, you can use too:


All these snippets won't trigger jQuery submit handler, avoiding a circular reference error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download