jQuery validation rule not working for nested html tags
I have a question abou开发者_StackOverflowt the validate method in jQuery and adding a rule to it, so say I have:
$("#myform").validate({
rules: {
zip: {
field: {
required: true,
maxlength: 5,
}
}
});
now my form layout looks like this:
<body>
<div>
<form id="myform">
<label>
<span>label</span>
<input name="zip" type="text" id="zip" class="required" size="50">
</label>
<label>
//some stuff here
</label>
</form>
</div>
</body>
Question is why is the validation not performed in zip? When I just have an input of text inside a body and nothing else it works.
Edit:
I just reviewed the site you linked and the jquery validate & delegate plugins are throwing 403's on your site (http://adityaherlambang.com/) . Update the url reference to those scripts and you should be good to go.
validate: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js
Original:
Looks like your validate js is a little off. Try using:
$("#myform").validate({
rules: {
zip: {
required: true,
maxlength: 4
}
}
});
Related fiddle: http://jsfiddle.net/gp4vB/
You did not close the Zip input tag. It should look like below:
<input name="zip" type="text" id="zip" class="required" size="50" />
First of all you can't put input
inside of label
. It should be organized like:
<label for="cname">Name</label>
<input type="text" id="cname" name="cname" />
And close your input
tag
<input name="zip" type="text" id="zip" class="required" size="50" />
$(document).ready(function () {
$("#myform").validate({
rules: {
zip: {
required: true,
maxlength: 4
}
}
});
});
精彩评论