Problem with add row in a table.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Problem with add row in a table.

    My code goes here ........

    [code=html]
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Sample Test</title>
    <script type="text/javascript">
    function add_row(){
    var row = document.getEle mentById('__deb asis__').cloneN ode(true);
    document.getEle mentById('origi nal_row').paren tNode.appendChi ld(row);
    }

    function copy_row(){
    var row = document.getEle mentById('origi nal_row').clone Node(true);
    row.setAttribut e("id","__debas is__");
    document.getEle mentById('clone _row').parentNo de.appendChild( row);
    }
    </script>
    </head>

    <body onload="copy_ro w()">
    <table width="100%" border="0" cellspacing="1" cellpadding="1" >
    <tr id="original_ro w">
    <td><input type="text"/></td>
    <td><input type="text"/></td>
    <td><input type="text"/></td>
    </tr>
    </table>
    <table width="100%" border="0" cellspacing="1" cellpadding="1" style="display: none">
    <tr id="clone_row" >
    </tr>
    </table>
    <input type="button" value="Add Row" onclick="add_ro w()"/>
    </body>
    </html>
    [/code]

    First time the row gets added fine. Next time if i add a row by giving some values of texts to last row it gets copied to the newly added row.
    But i cloned the empty row at onload time, so what does it happen?
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    I found the error.
    Actually what happened, the id gets duplicated.
    After a change to ....

    [code=javascript]
    function add_row(){
    var row = document.getEle mentById('__deb asis__').cloneN ode(t rue);
    row.setAttribut e("id",unique_i d);
    document.getEle mentById('origi nal_row').paren tNode .appendChild(ro w);
    }
    [/code]

    Comment

    Working...