Skip to main content
edited title
Link
Lightness Races in Orbit
  • 386.7k
  • 77
  • 670
  • 1.1k

jQuery : check Check if input empty on submit

Source Link
Osu
  • 1.1k
  • 2
  • 19
  • 34

jQuery : check if input empty on submit

I've been looking around for a solution to this, but can't seem to find any examples that work for me. Here's what I've got so far:

$("#register-form").submit(function(){
            if($(".required input").val() == '') {
                alert("Please fill in all the required fields (indicated by *)");
                $(".required").addClass('highlight');
                // $('input[type=submit]', this).attr('disabled', 'disabled');
                return false;
            }
        });

For some reason, when I submit the form with none of the required fields filled in (there are two), then it works, but if one of them is filled out, it doesn't.

Any ideas why?

Thanks

osu