If you want to validate the dynamically generated form using javascript:
You can use this code :
HTML :
<div id="example">
<form id="newForm">
<input type="text" name="email" id="email" value="mail" />
<button type="submit">validate</button>
</form>
</div>
<br/>
<button id="newform">Create New Form</button>
Javascript :
var validateObj = {
rules: {
email: {
email: true
}
}
};
$(function () {
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
// INITIALIZE plugin on the traditional form
var validated = $('#newForm').validate(validateObj);
$('#newform').one('click', function () {
var newform = '<form id="newForm2"><input type="text" name="email" id="email" value="bademail" /><button type="submit">validate</button></form>'
$('#example').append(newform);
// INITIALIZE plugin on the new form
var validate = $('#newForm2').validate(validateObj);
});
});
You have to include these two files also:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.js"></script>
Hope this will help you!
0 Comment(s)