Example : How to Validate/Check/Match Password and Confirm Password Box in HTML using JS.
<!doctype html>
<html>
   <head>
      <title>Codershelpline Code for Save</title>        
      <script>
	  function passmatch()
	   {					 
             if(document.form1.TxtPassword.value!=document.form1.TxtCpassword.value)
		{
		   alert("Password not Matched");
		   event.preventDefault();
		   document.form1.TxtPassword.value="";
		   document.form1.TxtCpassword.value="";
		   document.form1.TxtPassword.focus();
		}				   
              //if(document.form1.TxtPassword.value==document.form1.TxtCpassword.value)
		{
		   //alert("Password Matched");
		   //event.preventDefault();
		}				   
	     }        
        </script>        
    </head>
    <body>
       <form name="form1" id="form2" action="#" method="post">
	  <center>
	     <fieldset style="width: 600px">				
		<legend>Create New Student Account</legend>
		<table>
		   <tr>
		      <td>Serial No.</td>
		      <td>:</td>
		      <td><input type="text" name="TxtSlno"></td>
		   </tr>
		   <tr>
		      <td>Student Name</td>
		      <td>:</td>
		      <td><input type="text" name="TxtSname"></td>
		   </tr>						
		   <tr>
		      <td>Password</td>
		      <td>:</td>
		      <td><input type="password" name="TxtPassword"></td>
		   </tr>		   
		   <tr>
		      <td>Confirm Password</td>
		      <td>:</td>
		      <td><input type="password" name="TxtCpassword"></td>
		   </tr>						
		   <tr>
		      <td>Remarks</td>
		      <td>:</td>
		      <td><input type="text" name="TxtRem" value="N/A"></td>
		   </tr>
		   <tr>
		      <td></td>
		      <td></td>
		      <td>
                         <input type="submit" name="BtnSave" value="Save" 
                         onClick="passmatch()">
 			 <input type="reset" name="BtnReset" value="Reset">								
		      </td>
		   </tr>
		</table>
	     </fieldset>
          </center>
       </form>
    </body>
</html>

Loading


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.