Using HTML5 required field validation

HTML5 provides a built in functionality for required field validation. In the following code, both the user name and password are having a property set as required=”required”. When this property is set, the form will not submit unless the values are provided in the text boxes

<form id="form1" name="form1" method="post" action="">
 <table border="1">
 <tr>
 <td>User Name</td>
 <td><input id="txtusername" name="txtusername"
  type="text" required="required" /></td>
 </tr>
 
 <tr>
 <td>Password</td>
 <td><input id="txtpasswd" name="txtpasswd" type="password" required="required" /></td>
 </tr>
 
 <tr>
 <td></td>
 <td><input type="submit" /></td>
 </tr>
 </table>
</form>

 

Add a Comment

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