validating dynamically added textboxes using javascript
<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
  var counter = 0;
            function addNew() {
              var mainContainer = document.getElementById('form2');
                var newDiv = document.createElement('div');
                 var newText = document.createElement('input');
                var newlabel = document.createElement('label');
                newText.type = "input";
                newText.value = counter;
                newlabel.type = "label";
                newlabel.value = counter;

                 var newDelButton = document.createElement('input');
                newDelButton.type = "button";
                newDelButton.value = "Delete";
                  newDiv.appendChild(newText);
                  newDiv.appendChild(newlabel);
                    mainContainer.appendChild(newDiv);
                 counter++;
                  newDelButton.onclick = function (){
                   mainContainer.removeChild(newDiv);
                }
            }
  var bigger = 0;
            function addNew1() {
              var mainContainer1 = document.getElementById('form3');
                var newDiv1 = document.createElement('div');
                 var newText1 = document.createElement('input');
                newText1.type = "input";
                newText1.value = bigger;
                 var newDelButton1 = document.createElement('input');
                newDelButton1.type = "button";
                newDelButton1.value = "Delete";
                  newDiv1.appendChild(newText1);
                    mainContainer1.appendChild(newDiv1);
                bigger++;
                  newDelButton1.onclick = function () {
                   mainContainer1.removeChild(newDiv1);
                }
            }




    function formvalidation() {
        var x = document.getElementById("firstname").value;
        var y = document.getElementById("secondname").value;
        var z = document.getElementById("address").value;
        var a = document.getElementById("mobilenumber").value;
        var b = document.getElementById("emailid").value;
        var exp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var flag = 0;


        if (x == null || x == "") {
            document.getElementById("lblmsg").style.display = "";
            document.getElementById("lblmsg").innerHTML = "enter first name";
            flag = flag + 1;
        }
        else {
            document.getElementById("lblmsg").style.display = "none";

        }
        if (y == null || y == "") {
            document.getElementById("lblmsg1").style.display = "";
            document.getElementById("lblmsg1").innerHTML = "enter second name";
            flag = flag + 1;
        }
        else {
            document.getElementById("lblmsg1").style.display = "none";
        }

        if (z == null || z == "") {
            document.getElementById("lblmsg2").style.display = "";
            document.getElementById("lblmsg2").innerHTML = "enter your address";
            flag = flag + 1;
        }
        else {
            document.getElementById("lblmsg2").style.display = "none";
        }

        if (a == "") {
            document.getElementById("lblmsg3").style.display = "";
            document.getElementById("lblmsg3").innerHTML = "enter mobile number";
            // a.focus();
            flag = flag + 1;
        }
        else {
            document.getElementById("lblmsg3").style.display = "none";
        }

        if (isNaN(a)) {
            document.getElementById("lblmsg3").style.display = "";
            document.getElementById("lblmsg3").innerHTML = "eneter only numbers";
            // a.focus();
            flag = flag + 1;
        }
        else {
            document.getElementById("lblmsg3").style.display = "none";
        }
        if (a.length &gt; 10 || a.length &lt; 10) {
            document.getElementById("lblmsg3").style.display = "";
            document.getElementById("lblmsg3").innerHTML = "mobile number should be 10 digit one";
            //  a.focus();
            flag = flag + 1;
        }
        else {
            document.getElementById("lblmsg3").style.display = "none";
        }

        if (b == "") {
            document.getElementById("lblmsg4").style.display = "";
            document.getElementById("lblmsg4").innerHTML = "enter email id";
            flag = flag + 1;
        }
        else {
            document.getElementById("lblmsg4").style.display = "none";
        }
        if (exp.test(b) == false) {
            document.getElementById("lblmsg4").style.display = "";
            document.getElementById("lblmsg4").innerHTML = "correct format is xyz@x.com";
             flag=flag+1;
         }

        else {
            document.getElementById("lblmsg4").style.display = "none";
        }
         if(input == ""){
        document.getElementById("unique_label_id").innerHTML="enter ur mobile number";
        flag = flag+1;
        }


        if (flag &gt; 0) {
            return false;
        }
        else {
            return true;
        }
    }
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

First Name: &lt;input type="text" id="firstname"/&gt;
&lt;label id="lblmsg" style="color:Red;" &gt;&lt;/label&gt;&lt;br /&gt;
Second Name:&lt;input type="text" id="secondname"/&gt;
&lt;label id="lblmsg1" style="color:Red;" &gt;&lt;/label&gt;&lt;br /&gt;
Address:&lt;input type="text" id="address" /&gt;
&lt;label id="lblmsg2" style="color:Red;" &gt;&lt;/label&gt;&lt;br /&gt;


&lt;form id="form2" method="get" &gt;
&lt;div&gt;Mobile number:&lt;input type="text" id="mobilenumber" name="txt1" class="txt11" /&gt;
&lt;label id="lblmsg3" style="color:Red;"  class="lbl11"  &gt;&lt;/label&gt;&lt;input type="button" value="Add" onclick="addNew()" /&gt;&lt;/div&gt;

&lt;/form&gt;


&lt;form id="form3" method="get" &gt;
&lt;div&gt;Email id:&lt;input type="text" id="emailid"  /&gt;
&lt;label id="lblmsg4" style="color:Red;" &gt;&lt;/label&gt;&lt;input type="button" value="Add" onclick="addNew1()" /&gt;&lt;/div&gt;
&lt;/form&gt;
&lt;input type="button" value="Submit" onclick=" return formvalidation()"/&gt;
&lt;input type="button" value="Clear"  onclick="reset()"/&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Here i need to validate all the text boxes added dynamically please help me out.
in my above code if i click add button it will generate textboxes and also i have assigned
labels to them all i need is to validate them please help me out</p>

<p>Thanks</p>
