0

I am attempting to create a simple validation function for my contact form. Click here At the moment, once details are submitted the form keeps display:none even when entries are incorrect. I have tried to target the form id Which doesn't seem to be working either.

below is a snippet of my function

 var form = $('#ajax-contact');
 var formMessages = $('#form-messages');



  form.validate();
  $(form).submit(function(e) {

      if ($('#ajax-contact').valid()) {

        $('#ajax-contact').validate({
            rules: {
              name: {
                rangelength: [2, 40],
              },
              email: {
                rangelength: [2, 40],
                email: true,
                required: true
              },
              errorClass: "error",
              highlight: function (input) {
                $(input).closet('.required').removeClass('has-success').addClass('has-error');
              }
            }
        })

      } else {
        $("#ajax-contact").css({'display:block'});
        console.log('not working');
      }
  })
3
  • css link you can't use an array when update the style Commented Aug 4, 2015 at 13:23
  • 1
    You've also misspelt closest as closet. Commented Aug 4, 2015 at 13:27
  • please read the docs for the validation plugin again. you are setting up validation rules in the 'submit' event handler. this has to be done initially instead. if you do that you have to use an 'invalid' handler if you want to respond to an invalid form since the validation framework will suppress form submit's if the form is invalid. Commented Aug 4, 2015 at 13:34

2 Answers 2

9

.css should be used this way:

$("#ajax-contact").css('display','block');

and if you have multiple .css to be set then you can go with

$("#ajax-contact").css({'display':'block','position':'relative'});
Sign up to request clarification or add additional context in comments.

Comments

0

Try css({display: "block"}) as it takes an object as options. Not an array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.