javascript - JSP submits the form even though js returns false -


i'm trying validate form. trying confirm passwords. js shows alert , function return false still submits form next page.

<html> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8">     <title>jsp page</title>     <script>         function validatepassword(){             var password=document.form1.password.value;             var cpassword=document.form1.cpassword.value;             if(password!=cpassword){                 alert("password not match");                 return false;             }else{                 return true;             }         }     </script> </head> <body>     <h1>hello world!</h1>     <form name="form1" onsubmit="validatepassword();" action="login.jsp">         <table width="80%">             <tr>                 <td style="text-align: center;width:40%">password<font color="red">*</font>:</td>                 <td style="text-align: center"><input type="text" name="password" required size="35"></td>             </tr>             <tr>                 <td style="text-align: center">confirm <font color="red">*</font>:</td>                 <td style="text-align: center"><input type="text" name="cpassword" required size="35"></td>             </tr>             <input type="submit">      </form> </body> </html> 

your handler not returning anything, use this:

onsubmit="return validatepassword();" 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -