Tuesday, 27 August 2013

Jquery validation occurs only for the first dynamic control not for other dynamic controls

Jquery validation occurs only for the first dynamic control not for other
dynamic controls

I have used jquery validation plugin for validation purpose. I am creating
dynamic controls and adding rules to that controls but while clicking the
submit button only first field is validated other fields are not
validated.If the first field value is satisfied the form is submitted but
other fields are not considered. How to resolve this issue. Any help would
be appreciated.
Code:
<script type="text/javascript">
$(document).ready(function () {
var count = 0;
$("#dynamicControlForm").validate();
$("#AddControls").click(function () {
count++;
var elements = "<input type='text' id='txt" + count +
"'class='required'/><br/></br>";
$(elements).appendTo("#dynamicControlForm");
$(".required").rules("add" + count, "required");
});
});
</script>
<div id="DynamicControlsContainer">
<input type="button" name="CreateControl" value="AddControl"
id="AddControls" />
<form action="/" method="post" id="dynamicControlForm">
<input type="submit" name="DynamicControl" id="btnDynamicSubmit"
value="Submit" />
</form>
</div>
Image:

No comments:

Post a Comment