droo
droo

Reputation: 25

jquery page refreshes regardless of return false

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

Answers (2)

user216084
user216084

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

keshu_vats
keshu_vats

Reputation: 442

Use return false; in click function.

Upvotes: 1

Related Questions