Search code examples
jqueryvalidationsyntaxidentifier

jquery form validation code gets uncaught syntax error


I get "uncaught syntax error unexpected identifier"

I can't seem to find the syntax error. Im using the same code from an Lynda.com tutorial and it worked for him. Alas I hand typed the text, but it looks the exact same.

$(".member-form").submit(function() {
              var abort = false;
              $("div.error")remove();
              $(':input[required]')each(function() {
                  if ($(this).val()=== '') {
                      $(this).after('div class="error">This is a required field</div>');
                      abort = true;
                  }

              });  //go through each required value
              if (abort) { return false;} else {return true;}
          }); //on submit

any help appreciated as I just dont see anything wrong above


Solution

  • missing period before remove()

    $("div.error").remove(); 
    //            ^ add period
    

    and each()

    $(':input[required]').each(
    //                   ^ add period