mercredi 26 octobre 2016

Trying to handle required condition in Safari. I'd like to prevent my else condition from firing if any input is missing

When I run this code, my if AND else statements run. I'm assuming it has something to do with my for loop, but am hitting a wall.

$('#patientForm').submit(function(e) {
    var ref = $(this).find("[required]");

    $(ref).forEach(function() {
        console.log(ref.length);
        if ($(this).val() === '') {
            alert("Required field should not be blank.");

            $(this).focus();

            e.preventDefault();
            //  return false;
        } else {
          console.log("else statement is running");

Aucun commentaire:

Enregistrer un commentaire