before a submit-action is fired i´m doing a little check before:

$(document).ready(function(){
$("#submit").submit(function(e){

e.preventDefault();

var check = $("#check").val();

        if(check == 1) {
            $("#submit").submit();
        } else {
            alert"input-hidden value is wrong")
        }

}

});
});

So i am checking if a value of a input-hidden-value is set to 1.

If it is, the form action should be processed, but instead i get this error:

too much recursion

anybody could help with this?

EDIT:

In this line:

$("#submit").submit();

this part:

#submit

is underlined, why?

有帮助吗?

解决方案

It is because calling $("#submit").submit(); again triggers the submit event which will again invoke the submit handler thus creating an infinite recursive loop... call the dom elements submit method instead like this.submit()

or use the preventDefault() only if the value is invalid else allow the default action to continue

$(document).ready(function () {
    $("#submit").submit(function (e) {
        var check = $("#check").val();
        if (check != 1) {
            e.preventDefault();
            alert("input-hidden value is wrong")
        }
    });
});

其他提示

You shouldn't call $("#submit").submit() to allow submit to happen, this causes your handler to be called over and over. Instead, you should move preventDefault() after the error alert() and return true instead of calling submit().

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top