Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Validate Registration Form Before Submit on Button Click

Oct 4, 2013
Introduction

Here I will explain how to validate user registration form using jQuery on submit or jQuery validate form before submit on button click.
 
Description:


To implement this we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title>jQuery 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>
Live Demo

To check for live demo try to click on below button
UserName
First Name
Location

Note: if you want to use for asp.net controls replace $("#txtlocation").val(); you’re your asp.net control id like this $("#<%=txtlocation.ClientID %>").val()

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

6 comments :

Anonymous said...

sir, i have been following your blogs, since a long time. Am an ASP.NET, C#, SQL programmer. Please, i've checked and this is the only way i could contact you. I will like to talk to you. Please you can Email me on Wizston@hotmail.com.
Thanks in advance sir.

Anonymous said...

ankita kuraneeeee

Anonymous said...

Hi sir,
same implementation i want to do in mvc 2 application can u please help me.

Anonymous said...

good post.

Anonymous said...

Nice . Thank You . .

Anonymous said...

good job

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.