var isCommitted = false;//Whether the form has been submitted, Default is fa"/> var isCommitted = false;//Whether the form has been submitted, Default is fa">

Home >Web Front-end >JS Tutorial >How to prevent repeated submission of forms using js

How to prevent repeated submission of forms using js

一个新手
一个新手Original
2017-09-18 10:41:331686browse


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>

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!

Statement:
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