0

I'm writing a registration form script with jquery validation and need to pass a variable to the submit button so that if there is an error the form will not submit. Here is my code for one row in the form:

        function check_email(){
            var email = $('#email').val();
            var filter = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
            if(!filter.test(email)){
                $('.emailStatus').removeClass("success").addClass("error"); 
            }
            else {
                $('.emailStatus').removeClass("error").addClass("success");
                [SOMETHING TO INDICATE NO ERROR OCCURS]
            }
        }

Then when I submit the form I need it to be able to find that NO Errors occur based on the [SOMETHING TO INDICATE NO ERRORS] line and perform a function. I'm sorry if this isn't clear but I don't have much experience with Javascript but would love if if I could get this form to work. Could it be done with a variable in the if statement?

Thank you

Sparky
  • 96,628
  • 25
  • 194
  • 277
  • have you looked at ".submit()": http://api.jquery.com/submit/ ? – varnie Mar 09 '13 at 20:22
  • What do you mean with error? Do you mean a JavaScript exception or an invalid email address? – Fabian Lauer Mar 09 '13 at 20:22
  • I basically mean that I want to add something onto the else condition to indicate that there is no error in the function - I then want to be able to use it when I submit the form - So, if there are no errors, the form will submit, else, does not do anything – user2152265 Mar 09 '13 at 20:32
  • Try enabling and disabling the submit button? – James Coyle Mar 09 '13 at 20:54
  • What do you mean you're writing it `"with jquery validation"`?... jQuery doesn't have any built-in form validation. You'd have to write validation from scratch (presumably what you're already doing), or use a jQuery plugin. – Sparky Mar 09 '13 at 21:57
  • I'm validating the input "live" if that makes sense - So if an invalid username is added it alerts them straight away and it all seems to work but I need to run another check as the submit button is pressed just to make sure there are no invalid field highlighted – user2152265 Mar 09 '13 at 22:05

0 Answers0