I have two forms without id, I could have more, when I try to validate with JQuery Validation Plugin It is successful but the message is placed always inside first form.
<form class="myform" action="http://www.google.com">
<input type="text" name="mytext"/>
<button class="mybutton">Send</button>
</form>
<form class="myform" action="http://www.google.com">
<input type="text" name="mytext"/>
<button class="mybutton">Send</button>
</form>
The JQuery Validation is
<script>
$(function () {
$('.myform').validate({
rules: {
mytext: 'required'
},
messages: {
mytext: 'Required field'
}
});
$('.mybutton').click(function () {
var form = $(this).closest('.myform');
console.log("Action form is: " + form.attr('action'));
form.valid();
});
});
</script>
When I press the button, I know the validation is successful because the output is Action form is: http://stackoverflow.com when I press the first button, and Action form is: http://www.google.com when I press the second button.
Is there any way to place the error in the correct form?