2

I am sure I am missing something somewhere, but I can't see where. I am trying to use the jQuery validate script but get this error continually. I am pretty sure all the files are in the right place etc. This is in the head:

<script src="scripts/jquery.min.js"></script>
<script src="scripts/jquery.validate.min.js"></script>
<script>
$(document).ready(function() {
    $('#form1').validate();
}); // end ready
</script>

then my form is as follows:

  <p>
    <label for="name">Your name:
    </label><br />
    <input name="name" type="text" class="required" title="Please enter your name." id="name" maxlength="80" />
  </p>

  <p>
    <label for="email">Your email address:</label><br /><input name="email" type="text" class="required email" title="Please enter a valid email address." id="email" maxlength="100" />
  </p>

  <p>
    <label for="phone">Your contact number:</label><br />
    <input name="phone" type="text" class="required" title="Please enter your phone number" id="phone" maxlength="50" />
  </p>

  <p>
    <label for="message">Message:<br />
    </label>
    <textarea name="message" id="message" cols="50" rows="5"></textarea>
  </p>
  <p>
    <input name="Submit" type="submit" class="form" id="Submit" value="Submit" style="width:100px" />
  </p>

</form>

Thanks for any help!

4
  • First, check your selector is correct -- try alert($("#form1").serialize())?
    – McGarnagle
    Commented Nov 22, 2012 at 23:17
  • Is the validate script loading properly? Commented Nov 22, 2012 at 23:22
  • Thanks for your help with this - with the 'alert' I get a blank alert box. The validate script is definitely there, but I am not sure how to get the 2 talking...I've used the same scripts previously with no issues.
    – Nicola
    Commented Nov 23, 2012 at 10:44
  • I'm also having this exact same problem, when I put the alert suggested by @dbaseman into my ready() function right before the validate call, it does show the form information. But I'm still getting this error. My Javascript error console shows that the jquery and validate plugins are loading, and I'm taking this example basically literally from the documentation, but it's failing in this same way. Commented Feb 3, 2013 at 23:34

2 Answers 2

4

I just ran into this problem and found two issues that caused this:

I accidentally had the jquery reference at the end of the HTML file to speed up loading. Moving this up above where I was doing the .validate() call resolved that. Example:

<script>
   $(document).ready(function(){
      $('#commentForm').validate();
   });
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>

I also had a problem where I accidentally loaded the jquery twice, once after the validation load. Example:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $('#commentForm').validate();
   });
</script>

This is what I needed to have:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<script>
   $(document).ready(function(){
      $('#commentForm').validate();
   });
</script>
1

I had the same problem within a rails project.

My problem was sovled after I deleted the public/assets folder, because this caused the project to load the jquery library multiple times (the original one and the precompiled one).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.