带有警报弹出窗口的JQuery表单验证-警报仍与有效提交一起显示 [英] JQuery form validation with alert popup - alert still being shown with a valid submit

查看:129
本文介绍了带有警报弹出窗口的JQuery表单验证-警报仍与有效提交一起显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jquery validate函数进行表单验证.到目前为止,我一直将错误消息附加到page元素,但是现在我想在警报弹出窗口中显示它. 当用户未选择任何内容时,警报弹出窗口会成功显示错误消息,但是当用户提交有效表单时,弹出窗口仍会出现(这次没有错误消息).

I'm using the Jquery validate function for my form validation. So far I've been appending the error message to a page element, but I now want to display it in an alert popup. The alert popup successfully displays the error message when the user has not selected anything, however the pop still appears when they submit a valid form (this time without the error message).

如何在提交有效表单后阻止弹出窗口显示?

How do I stop the popup from appearing after a valid form submission?

这是我的js代码,我已经实现了单选按钮的警报.您可以在 http://hiplogger.hip-zone.co.za/上看到此操作合作伙伴/手机

Here is my js code, I've implemented the alert for radio buttons. You can see this in action on http://hiplogger.hip-zone.co.za/partner/mobile

$("#quickieform").validate({
    rules: {
        answer: "required"
    },
    answer: {
        answer: "Please make a selection"
    },
    errorPlacement: function(error, element) {
        if ( element.is(":radio") )
            alert(error.html());

        else if ( element.is(":checkbox") )
            error.appendTo( ("#alertbox") );

        else
            error.appendTo( ("#alertbox") );
    },
    submitHandler: function(form) {
        // do other stuff for a valid form
        form.submit();
    },
    success: function(label) {
        // set   as text for IE
        label.html(" ").addClass("checked");
    }
});

推荐答案

感谢您的回复.我让它工作了,但我不知道为什么会工作.我所做的只是最后删除了成功:"部分,所以我的代码最终看起来像这样……

Thanks for your response. I got it working but I've no idea why its working. All I did was to take out the "success:" section at the end, so my code ended up looking like this...

$("#quickieform").validate({
    rules: {
            answer: "required"
        },
    invalidHandler: function(form, validator) {

    },
    errorPlacement: function(error, element) {
        if ( element.is(":radio") && error.html != "")
           // error.appendTo( ("#alertbox") );
            alert(error.html());

        else if ( element.is(":checkbox") )
           // error.appendTo( ("#alertbox") );
        alert(error.html());

        else
            error.appendTo( ("#alertbox") );
    },
    submitHandler: function(form) {
            form.submit();
    }

 })

这篇关于带有警报弹出窗口的JQuery表单验证-警报仍与有效提交一起显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆