NOTE: I referred these questions Qn1 , Qn2 before asking this . But honestly the answers are not working. Please suggest a solution..
I am doing validation to my input fields using jquery validation plugin. My code works fine when all the tags are kept inside a form tag and accessing it in jquery like, $("#formID").validate()
--> this is working fine... But I want to achieve the same for a div
instead of a form.
I tried it like this: $("#divID").validate()
but it's not working...
Below is my code. please take a look and tell me how to achieve it for a div
.
<script type="text/javascript">
$(document).ready(function () {
$("#content").validate({
onfocusout: true,
rules: {
fullname:
{
lettersonly: true,
required: true
},
age:
{
required: true,
number: true,
min: 20,
max:98,
nowhitespace:true
}
},
messages: {
fullname: "Please specify your name.",
age:"Please enter your correct age."
}
});
});
</script>
<div id="content">
<p>
<label for="fullname">Full name:</label>
<input type="text" name="fullname" id="fullname" /><br />
<label for="age">Age</label>
<input type="text" name="age" />
</p>
<p>
<button id="submit" value="">Search User</button>
</p>
</div>