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 > Article > Web Front-end > How to prevent repeated submission of forms using js
Through js control, set a Boolean value for judgment. Change the value after submission, and then submit again and it will not pass.
<!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!