Reputation: 149
Basic form of the code is given below that i want rectified. while running the code once it reaches .show() function the page is getting refreshed. I don't want that. Can you help me with this dilemma!!!! Please see the code below :
Code:
$(document).ready(function() {
$("#mandate").hide();
$("#submit").click(function() {
var password = $("#password").val();
if(password=='') {
$("#mandate").show();
}
else {
alert("Form Submitted Successfully..!!");
}
}
}
HTML:
<p id="mandate"><font color="red">Password is mandatory*</font></p>
Upvotes: 2
Views: 42
Reputation: 6264
Add return false;
to your code.
$(document).ready(function() {
$("#mandate").hide();
$("#submit").click(function() {
var password = $("#password").val();
if(password=='') {
$("#mandate").show();
return false;
}
else
{
alert("Form Submitted Successfully..!!");
}
});
The return false will return false to the event. That tells the browser to stop following events, like follow a link. It is similar to event.preventDefault()
Upvotes: 3