Share on Google+Share on Google+

jQuery 'submit' form event

Advertisement
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

Advertisements

Advertisement

Posted on: August 4, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.