Code that prevents repeated submission (Javascript) in JSP

Source: Internet
Author: User

DocumentStruts2 provides a repeat commit check mechanism, but what I want is not to bring up an error page, but to execute only one commit as nothing happens.

1. Set a variable and a variable, which can only be submitted once.

Reference content is as follows:

<Script type = "text/javascript">
Function checkSubmit (){
If (checkSubmitFlg = true ){
Return false;
}
CheckSubmitFlg = true;
Return true;
}
</Script>

<Form onsubmit = "return checkSubmit ();" method = "post">

  Method 1 is effective in both IE6 and FIREFOX experiments.

2. How to disable the button

  Because our server is too slow, the buttons are grayed out to provide a better user experience.

Reference content is as follows:

<Script type = "text/javascript">
Function disableSubmit (form ){
Var elements = form. elements;
For (var I = 0; I <elements. length; I ++ ){
If (elements [I]. type = 'submit '){
Elements [I]. disabled = true;
}
}
}
</Script>

<Form name = "form1" onsubmit = "setTimeout ('disablesubmit (form1) ', 100) return checkSubmit ();" method = "post">

  If it is immediately disabled, the separate action settings of the button will become invalid. Therefore, a delay is required.

  Method 2 is valid in IE6. The error message is invalid in FIREFOX because the cause is unknown. But it is the second insurance. It doesn't matter.

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.