By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,598 Members | 1,894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,598 IT Pros & Developers. It's quick & easy.

Problem with add row in a table.

dmjpro
100+
P: 2,476
My code goes here ........

Expand|Select|Wrap|Line Numbers
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title>Sample Test</title>
  5. <script type="text/javascript">
  6. function add_row(){
  7.     var row = document.getElementById('__debasis__').cloneNode(true);
  8.     document.getElementById('original_row').parentNode.appendChild(row);
  9. }
  10.  
  11. function copy_row(){
  12.     var row = document.getElementById('original_row').cloneNode(true);
  13.     row.setAttribute("id","__debasis__");
  14.     document.getElementById('clone_row').parentNode.appendChild(row);
  15. }
  16. </script>
  17. </head>
  18.  
  19. <body onload="copy_row()">
  20. <table width="100%" border="0" cellspacing="1" cellpadding="1">
  21.   <tr id="original_row">
  22.     <td><input type="text"/></td>
  23.     <td><input type="text"/></td>
  24.     <td><input type="text"/></td>
  25.   </tr>
  26. </table>
  27. <table width="100%" border="0" cellspacing="1" cellpadding="1" style="display:none">
  28.   <tr id="clone_row">
  29.   </tr>
  30. </table>
  31. <input type="button" value="Add Row" onclick="add_row()"/>
  32. </body>
  33. </html>
  34.  
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?
Aug 5 '08 #1
Share this Question
Share on Google+
1 Reply


dmjpro
100+
P: 2,476
I found the error.
Actually what happened, the id gets duplicated.
After a change to ....

Expand|Select|Wrap|Line Numbers
  1. function add_row(){
  2.     var row = document.getElementById('__debasis__').cloneNode(t  rue);
  3.     row.setAttribute("id",unique_id);
  4.     document.getElementById('original_row').parentNode  .appendChild(row);
  5. }
  6.  
Aug 5 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.