开发者

jQuery intercept form submission

开发者 https://www.devze.com 2023-01-13 22:03 出处:网络
I have number of conditions i\'d like to check before submitting a form so I\'ve created: $(\"Step2_UpdateCartForm\").submit(function () {

I have number of conditions i'd like to check before submitting a form so I've created:

$("Step2_UpdateCartForm").submit(function () {
    if (!procssingEmails) {

        return true;
    } else {
        return false;
    }

And I have a number of events that could result in a form submission so i have something like:

function fireUpdateCart() {
    if (isUpdateCartPending) {
        clearCartOptio开发者_如何学PythonnDefaultValues();
        $("#Step2_UpdateCartForm").submit();
    }
}

in a few different places. I'm expecting the above statement to send processing to that first code block but instead, the form is being submitted.

Am i wrong to expect my validation block to be processed


You are missing a "#" identifier from your event definition. This is the likely cause of your problem. The first line should read:

$("#Step2_UpdateCartForm").submit(function () {

   ^


There's a missing # in your selector. You should use the following:

$("#Step2_UpdateCartForm").submit(function () {
    if (!procssingEmails) {

        return true;
    } else {
        return false;
    }

And BTW, maybe your "procssingEmails" is misspelled, isn't it?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号