Reputation: 25
Hi I have been struggling with this code for a while now I am trying to validate a form using jquery without but the page refreshes regardless of return false.
Here is my code
$('.btn-submit').click(function () {
$('.signup input').each(function () {
if ($(this).val() == name) {
$('<p>Please enter your ' + $(".default-value").attr("value") + ' </p>').appendTo('.form_error');
return false;
}
});
Upvotes: 0
Views: 89
Reputation:
Instead of return false
, try preventDefault
on the event of your submit
button, as follows:
$('.btn-submit').click(function(e) {
$('.signup input').each(function() {
if($(this).val() == name) {
$('<p>Please enter your '+ $(".default-value").attr("value") + ' </p>').appendTo('.form_error');
e.preventDefault();
}
});
});
Upvotes: 1