Reputation: 21
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!
Upvotes: 2
Views: 5417
Reputation: 3857
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).
Upvotes: 1
Reputation: 1261
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>
Upvotes: 4