Home > Web Front-end > JS Tutorial > body text

How to prevent repeated submission of forms using js

一个新手
Release: 2017-09-18 10:41:33
Original
1668 people have browsed it


Through js control, set a Boolean value for judgment. Change the value after submission, and then submit again and it will not pass.

The code is as follows:

<!DOCTYPE HTML><html>
  <head>
    <title>Form表单</title>
  </head>

   <script type="text/javascript">
        var isCommitted = false;//表单是否已经提交标识,默认为false
        function dosubmit(){
            if(isCommitted==false){
                isCommitted = true;//提交表单后,将表单是否已经提交标识设置为true
                return true;//返回true让表单正常提交
            }else{                return false;//返回false那么表单将不提交
            }
        }    </script>
  <body>
      <form action="${pageContext.request.contextPath}/servlet/DoFormServlet" onsubmit="return dosubmit()" method="post">
        用户名:<input type="text" name="username">
        <input type="submit" value="提交" id="submit">
    </form>
  </body>
  </html>
Copy after login

The above is the detailed content of How to prevent repeated submission of forms using js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template