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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cloning a table as child to each cloned cells

    Hi all

    I am using Internet Explorer 8

    I have 2 Tables

    Table1: 1 row 2 columns
    Table2: 1 row 1 column

    I want to clone table 1 to table 2 making it a child of the cell.
    I thent want to clone Table1 making it a child to each of the cloned cells and so on.

    The posted code is as close as I have gotten.

    Code:
    <html>
    <head>
        <script type="text/javascript">
    var x=0;
    var y=0;
    var z=0;
    
    function Clone () 
    {
         	var clonedTable = srcTable.cloneNode (true);
                	clonedTable.id = "";    // clear the id property of the cloned table
                	var t=document.getElementById('srcTable2');
        	var s=t.rows[0].cells[0];
    	var u=s.children[0];
    
    	while(u != null)
    	{
    
    			alert(u)
    			u=u.children[0];
    			if  (u != null)
    			{
    				alert("here2")
    				s=u;
    			}
    	}
    	
    	s.appendChild (clonedTable);
    }
        </script>
    </head>
    <body>
        <div id="container">
            <table id="srcTable" border="1px">
                <tr>
                    <td>Apple</td>
                    <td>Peach</td>
                    <td>Cherry</td>
                </tr>
            </table>
        </div>
        <div id="container2">
            <table id="srcTable2" border="1px">
                <tr>
                    <td>1</td>
                </tr>
            </table>
        </div>
        <br /><br />
        <button onclick="Clone();">Clone Table!</button>
    </body> 
    </html>
    As you can see from the script I can clone Table1 making it a child of the cell in table 2 but can only make further children in row1 column 1 of the children and cannot access the other 2 cells.

    Any help would be gratefully received.

    Many thanks in advance.

    Drist

  • #2
    Regular Coder
    Join Date
    Jul 2011
    Location
    India
    Posts
    496
    Thanks
    3
    Thanked 57 Times in 56 Posts
    Hi,

    Please check your code:

    Code:
    var s=t.rows[0].cells[0];
    each time you call Clone() function, it is accessing 1st cell of 1st row and it is getting cloned in same cell.

    You need to check the whole table and find out the empty cells and append trhe cloned table into it each time.

    Regards,
    Vikram

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes I know it is accessing 1st cell of 1st row and it is getting cloned in same cell.

    I did say this in my description. The problem is how to access the rest of the cells within the cloned table.

    Any other thoughts as to how this can be achieved would be very welcome.#

    with thanks in advance

    Drist


  •  

    Posting Permissions

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