Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Not able to add validation to the dynamic rows!

    Hi all,

    I have a dynamic table in which I can add rows using an add button.. The problem here is I am not able to validate the rows that are added dynamically.

    My Java Script code is as follows for adding the new rows:

    Code:
    var table = document.getElementById('tbodyId');
        var row = table.insertRow(rownumber);
    
        
        var cell1 = row.insertCell(0);
        var element1 = document.createElement("input");
        element1.type = "text";
        element1.id="active";
        element1.name="active";
        element1.onchange = "validation();";
        cell1.appendChild(element1);
    now my problem is the validation() function is not getting called when I am entering data into the textbox. Can anyone please help me and enlighten me as to what is wrong with this code?

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Code:
    <!doctype html>
    <head><title></title>
    </head><body>
    <table>  
    <tbody id="tbodyId">
    </table>
    <script>
     var table = document.getElementById('tbodyId');
    for(var i = 0; i<3; i++){
        var row = table.insertRow(-1);    
        var cell1 = row.insertCell(0);
        var element1 = document.createElement("input");
        element1.type = "text";
        element1.name="active[]";
        element1.onchange = function(){validation(this)};
        cell1.appendChild(element1);
    }
    function validation(el){alert(el.value)}
    </script>
      </body></html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •