Home Tutorial Jquery jQuery 'submit' form event

 
 

jQuery 'submit' form event
Posted on: August 4, 2010 at 12:00 AM
In this tutorial, we will discuss about the 'submit' form event of jQuery.

jQuery 'submit' form event

In this tutorial, we will discuss about the  'submit' form event of jQuery. In this example , In this example a text box and a button is given, when we hit the button, it will check/validate whether entered string is  "true" or not. If it is 'true' , it will show a message "Query is validated" and also a alert box to show the "success" message. The alert box will show only when "submit" event return 'true' to 'form'.

submitFormEvent.html

<!DOCTYPE html>
<html>
<head>
<style>

p { margin:0; color:blue; }
div,p { margin-left:10px; }
span { color:red; }
</style>
<script src="jquery-1.4.2.js"></script>
</head>
<body>
<p>Type 'true' to validate.</p>
<form action="javascript:alert('success!');">
<div>
<input type="text" />

<input type="submit" />
</div>
</form>
<span></span>
<script>

$("form").submit(function() {
if ($("input:first").val() == "true") {
$("span").text("Query is Validated...").show();
return true;
}
$("span").text("Query is Not valid!").show().fadeOut(1000);
return false;
});
</script>
</body>
</html>

OUTPUT

When we enter "true", it will display :

Download Source Code

Click here to see demo

Related Tags for jQuery 'submit' form event:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.