Reputation: 253
I'm having trouble getting jQuery's validation plugin to work. I'm pulling in both jquery.js and the jquery.validate.js successfully. My script is as follows:
$(document).ready(function($) {
$("#apply").validate({
rules: {
firstname: "required",
surname: "required",
secret: {
required: true,
minlength: 5
},
verify_secret: {
required: true,
minlength: 5,
equalTo: "#secret"
},
email: {
required: true,
email: true
},
},
messages: {
firstname: "Please enter your firstname",
surname: "Please enter your surname",
secret: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
verify_secret: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same password as above"
},
email: "Please enter a valid email address",
}
});
});
Here's my markup:
<form method="post" action="apply.php" id='apply'>
<input type='text' name='firstname' id='firstname' value=''/>
<input type='text' name='surname' id='surname' value=' '/>
<input type='text' name='email' id='email' value='Your Email Address'/>
<label for='secret'>Your Chosen Password</label>
<input type='password' name='secret' id='secret'/>
<label for='verify_secret'>Verify Your Password</label>
<input type='password' name='verify_secret' id='verify_secret'/>
<input type='submit' name='submit' value='Submit'/>
</form>
Is there some dependency I'm missing? I'm getting no error messages or anything else that might help me fix the issue.
Upvotes: 0
Views: 815
Reputation: 98758
As per jQuery documentation, $().ready(function() {
is "not recommended".
Since you mention nothing about other JavaScript libraries also using the $
variable on your page, or anything about using noConflict() mode, just use the standard document.ready
function without passing the superfluous $
into it.
$(document).ready(function() { ... });
Here is a working demo of your code...
I also found/removed a couple of trailing commas. I noticed you have the same rules on both password fields. Since the second field is using the equalTo
rule, the other rules are redundant and could be removed. See: http://jsfiddle.net/tnuQa/
Upvotes: 3
Reputation: 6736
instead of this , i cant understand why you used jquery like this ?
$().ready(function($) {
Try
$(document).ready(function() {
Upvotes: 1