How to prevent repeated forms submitted by the jquery validation plug-in

Source: Internet
Author: User

Because the jquery validation Form Verification plug-in is applied in the project, submit the form after the validation is completed, and then disable the button.
There is a disablebtnpostback project in codeproject, but it works with jquery validation, Code Post the code first and remind everyone not to use the code in this case. The Code is as follows:
JS:
Code Copy code The Code is as follows: function disablebtn (btnid, newtext ){
Page_isvalid = NULL;
If (typeof (page_clientvalidate) = 'function '){
Page_clientvalidate ();
}
VaR BTN = Document. getelementbyid (btnid );
VaR isvalidationok = page_isvalid;
If (isvalidationok! = NULL ){
If (isvalidationok ){
BTN. Disabled = true;
BTN. value = newtext;
BTN. style. Background = "url(12501270608.gif )";
}
Else {
BTN. Disabled = false;
}
}
Else {
SetTimeout ("setimage ('" + btnid + "')", 10 );
BTN. Disabled = true;
BTN. value = newtext;
}
}
Function setimage (btnid ){
VaR BTN = Document. getelementbyid (btnid );
BTN. style. Background = 'url(12501270608.gif )';
}

Front-end Page code:
CodeCopy codeThe Code is as follows: <asp: button id = "btnone" tabindex = "0" runat = "server" text = "Submit"
Onclick = "btnone_click"
Onclientclick = "disablebtn (this. ID, 'submitting ...')"
Usesubmitbehavior = "false"/>

Okay, the following code solves the problem of submitting a form after the Form Verification of the validation plug-in is completed by the submit button. submit the form:
JS:
CodeCopy codeThe Code is as follows: $ (document). Ready (function (){
$ ("# Myform"). Validate ({
Submithandler: function (form ){
$ (Form). Find (": Submit"). ATTR ("disabled", true). ATTR ("value ",
"Submitting ...");
Form. Submit ();
}
})
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.