Hi All,
I tried a lots of way to validate a dynamic form. Validation is always
works with the element ID right?
Sometimes, it seems like the validation is working with the element
NAME. I give you this example.
[code=text]
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Dynamic Form Validation</title>
<script type="text/javascript" src="../lib/jquery.js"></script>
<script type="text/javascript" src="../jquery.validate.js"></script>
<script type="text/javascript">
    jQuery().ready(function(){
        var jsonRules = {
            rules: {
                full_name: {
                    required: true
                }
            }
        };
        jQuery("#test_form").validate(eval(jsonRules));
        var template = jQuery.format(jQuery("#template").val());
        function addRow(){
            jQuery(template(i++)).appendTo("#divPrimary");
            var j = i-1;
            jQuery("#address_"+j).rules("add", "required");
        }
        var i = 1;
        addRow();
        jQuery("#add").click(addRow);
    });

</script>
</head>

<body>
<textarea id="template" style="display:none">
    <div id="template_id_{0}">
    <p>Address: <input type="text" name="address" id="address_{0}" /></
p>
    </div>
</textarea>
<form action="" name="test_form" id="test_form" method="post">
<p>Name: <input type="text" name="full_name" id="full_name" /></p>
<div id="divPrimary"></div>
<p><input type="submit" name="Go" value="Go" /></p>
</form>
<button id="add">Add More</button>
</body>
 [/code]
Here, if you notice, I have added the dynamic content inside the
textarea. And the address has the fixed NAME(address). But the ID
increments dynamically.
Now, this dynamic form works perfectly when I increment the NAME like
ID. If the validation is happening with the ID, then why I am not
getting the validation?
Hope to get your views.

Thanks

Reply via email to