How to Validate Registration Form Before Submit on Button Click using Jquery c#
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1"> <title>Registration Form Validation</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"> </script> <script language="javascript" type="text/javascript"> $(function () { $('#btnvalidate').click(function () { var summary = ""; summary += isvaliduser(); summary += isvalidFirstname(); summary += isvalidLocation(); if (summary != "") { alert(summary); return false; } else { return true; } }) }) function isvaliduser() { var temp = $("#txtuser").val(); if (temp == "") { return ("Please Enter UserName" + "\n"); } else { return ""; } } function isvalidFirstname() { var temp = $("#txtfname").val(); if (temp == "") { return ("Please Enter firstname" + "\n"); } else { return ""; } } function isvalidLocation() { var temp = $("#txtlocation").val(); if (temp == "") { return ("Please Enter Location" + "\n"); } else { return ""; } } </script> </head> <body> <form id="form1"> <table align="center"> <tr> <td>UserName</td> <td> <input type="text" id="txtuser" /> </td> </tr> <tr> <td>First Name</td> <td> <input type="text" id="txtfname" /> </td> </tr> <tr> <td>Location</td> <td> <input type="text" id="txtlocation" /> </td> </tr> <tr> <td></td> <td> <input type="button" value="Validate" id="btnvalidate" /> </td> </tr> </table> </form> </body> </html> |
No comments:
Post a Comment