Is it possible to validate a <div> tag without any<form> tag?
am2222 opened this issue · 3 comments
am2222 commented
Hi,
I have div tag, I want to validate it using validate.js ..If I pass its Id to validator Can I validate it without any use of
rickharrison commented
Unfortunately no as this relies on onsubmit
and document.forms
am2222 commented
I made some changes to my code to use form for validating although it is not the complete code:
<form id="add" action="#">
<div >
<label>some text</label>
<div >
<input type="text" name="groupName" id="groupName">
</div>
<div >
<p><button type="button" id="reg" >ok</button></p>
</div>
</div>
</form>
This is the js for validation:
$(document).ready(function(){
$('#reg').click(function(){
var form = $("#add");
form.validate({
rules: {
groupName: {
required: false
}
},
messeges:{
groupName:{
required:"fill"
}
}
});
if (form.valid()== true){
alert('true');
}
});
});
when the document is ready it gives true message to me without validate the text field. can you find any problem in my code? I should say that do not want to use submit button because form already has a submit button an as I said this is just a part of my code.
am2222 commented
Please can some one help me? I am stuck on this problem yet.