Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jquery在不同的按钮单击中验证同一表单_Javascript_Jquery - Fatal编程技术网

Javascript 如何使用jquery在不同的按钮单击中验证同一表单

Javascript 如何使用jquery在不同的按钮单击中验证同一表单,javascript,jquery,Javascript,Jquery,edit txt,updatePassword是一种形式的两个按钮superAdminDetailsForm。我想在两个按钮点击中验证此表单。我在每次点击按钮时都写下了表单验证,但它不起作用。编辑txt按钮为文本类型,更新密码为按钮类型 $().ready(function() {$('#edit-txt').on('click', function() { $("#superAdminDetailsForm").validate({

edit txt
updatePassword
是一种形式的两个按钮superAdminDetailsForm。我想在两个按钮点击中验证此表单。我在每次点击按钮时都写下了表单验证,但它不起作用。编辑txt按钮为文本类型,更新密码为按钮类型

    $().ready(function() {$('#edit-txt').on('click', function() {
        $("#superAdminDetailsForm").validate({

                    rules: {
                        superadminEmail:{
                            required:true,
                            email:true
                        },  
                    }, 
                    messages: {
                            superadminEmail:"Please enter your Email id"
                    },
                    submitHandler: function(){
                    var formData =$("#superAdminDetailsForm").serialize();
                        $.ajax({
                            url:'/accounts',
                            type:'post',
                            datatype: 'json',
                            data: formData,
                            success : function(response){
                                if(response == "true"){
                                    window.location='/accounts';
                                } else {
                                     alert("false")
                                }
                            },
                            error: function (request,status, error) {
                            }
                        });
                    return false;
                }
            });

    });


    $('#updatePassword').on('click', function()  {$("#superAdminDetailsForm").validate({

            rules: {
                oldPassword:"required",
                newPassword:"required",
                confirmpassword:{
                    require :"true",
                    equalTo : "#oldPassword"
                } 
            },
             messages: {
                 oldPassword:"Please enter Old Password ",
                 newPassword: "Please enter New Password",
                 confirmpassword:"Retype password is incorrect"
             },
            submitHandler: function(){//to pass all data of a form serial
                 var formData =$("#superAdminDetailsForm").serialize();
                        $.ajax({
                            url:'/changePassword',
                            type:'post',
                            datatype: 'json',
                            data: formData,
                            success : function(response){
                                if(response == "true"){
                                    window.location = '/accounts';
                                } else {
                                    alert("password incorrect");
                                }
                            },
                            error: function (request,status, error) {
                            }
                        });
                    return false;
                }


        });
    });
});