JavaScript - to copy entire html table & its contents from object HTMLTableElement

Asked By anbu n on 17-Oct-11 02:53 AM
<table border="1" style="border-width:1px;border-style:solid;" runat="server" rules="all" id="ctl00_ContentPlaceHolder1_tblDynamic">
        <tbody><tr>
            <td><span id="ctl00_ContentPlaceHolder1_lblRow_0Col_0">CapEx</span></td><td><span>1year</span></td><td><span>2year</span></td><td><span>3year</span></td><td><span>4year</span></td><td><span>5year</span></td><td><span>6year</span></td>
        </tr>
<tr>
            <td><span id="ctl00_ContentPlaceHolder1_lblRow_1Col_0">Leasing Costs</span></td><td><input type="text" id="ctl00_ContentPlaceHolder1_TextBoxRow_1Col_0" value="RowNo:1 ColumnNo: 0" name="ctl00$ContentPlaceHolder1$TextBoxRow_1Col_0"></td><td><input type="text" id="ctl00_ContentPlaceHolder1_TextBoxRow_1Col_1" value="RowNo:1 ColumnNo: 1" name="ctl00$ContentPlaceHolder1$TextBoxRow_1Col_1"></td><td><input type="text" id="ctl00_ContentPlaceHolder1_TextBoxRow_1Col_2" value="RowNo:1 ColumnNo: 2" name="ctl00$ContentPlaceHolder1$TextBoxRow_1Col_2"></td><td><input type="text" id="ctl00_ContentPlaceHolder1_TextBoxRow_1Col_3" value="RowNo:1 ColumnNo: 3" name="ctl00$ContentPlaceHolder1$TextBoxRow_1Col_3"></td><td><input type="text" id="ctl00_ContentPlaceHolder1_TextBoxRow_1Col_4" value="RowNo:1 ColumnNo: 4" name="ctl00$ContentPlaceHolder1$TextBoxRow_1Col_4"></td><td><input type="text" id="ctl00_ContentPlaceHolder1_TextBoxRow_1Col_5" value="RowNo:1 ColumnNo: 5" name="ctl00$ContentPlaceHolder1$TextBoxRow_1Col_5"></td>
        </tr>

    </tbody></table>

----------------

the above table is dynamically created table,
 through javascript , i need to copy its innerHTML i.e, entire html tags with data to parent page
---
my java script code is..

function createDuplicate() {
    
    var isValid = true;
    var idprefix = 'ctl00_ContentPlaceHolder1_';
    var inner_gv = '';

    var tbl = document.getElementById(idprefix + 'tblDynamic');  
    var _div = document.getElementById(idprefix + 'pnlPopup');  
    
    var tbl_duplicate = document.getElementById('htmlTagValue');

    tbl_duplicate.innerHTML = _div.innerHTML;

    alert(tbl_duplicate.innerHTML);


}

in the above code "tblDynamic" is dynamically created table [object HTMLTableElement]
i can not get the innerHTML of the table










Jitendra Faye replied to anbu n on 17-Oct-11 03:06 AM
For that follow these stpe-

step1: Take one Div with Runat="Server" attribute.

<div runat ="server" id="div1">

</div>
step2: Put that tbale inside this div-

<div runat ="server" id="div1">

//put your table here
</
div>


step3: Use InnerHTML ptoperty to get all contents of Div like this-

string strContent =div1.InnerHtml ;
Try this and let me know.


anbu n replied to Jitendra Faye on 17-Oct-11 03:42 AM
nothing is coming... null is coming