how to copy the content of table and the content on hidden table in a page.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • froilan03
    New Member
    • Apr 2008
    • 2

    how to copy the content of table and the content on hidden table in a page.

    Hi,

    Please help me to solve this one. I have page with tables (including hidden tables), my problem is how can I copy both the content of the table.
    Here is my code snippets:

    [CODE=javascript]function copyTable(table Number) {

    // Get the table frame
    var tableIFrame = eval("generated Frame" + tableNumber);
    // Get the table
    var tableOnPage = tableIFrame.doc ument.getElemen tById("table" +
    tableNumber);
    // Clone this table, so that we can remove the links without changing
    the page
    var myTable = tableOnPage.clo neNode(true);

    var hiddenTableOnPa ge = document.getEle mentById
    ("tableIDHidden Field" + tableNumber);

    var myHiddenTable = hiddenTableOnPa ge.cloneNode(tr ue);

    var myTableHTML = "";

    // Run through stripping out links
    for (var i=0;i < myTable.documen t.all.length; i++) {
    if (myTable.docume nt.all(i).tagNa me == 'A') {
    myTable.documen t.all(i).remove Node(false);
    }

    }

    // Get the HTML for the table
    for (var i=0;i < myTable.documen t.all.length; i++) {
    if (myTable.docume nt.all(i).tagNa me == 'TH' ||
    myTable.documen t.all(i).tagNam e == 'TD') {
    myTableHTML += myTable.documen t.all
    (i).innerText + '\t';
    }
    if (myTable.docume nt.all(i).tagNa me == 'TR') {
    if (myTableHTML.le ngth > 1)
    myTableHTML += '\n';
    }
    }

    // Run through stripping out links
    for (var i=0;i < myHiddenTable.d ocument.all.len gth; i++) {
    if (myHiddenTable. document.all(i) .tagName == 'A') {
    myHiddenTable.d ocument.all(i). removeNode(fals e);
    }

    }

    // Get the HTML for the hidden table
    for (var i=0;i < myHiddenTable.d ocument.all.len gth; i++) {
    if (myHiddenTable. document.all(i) .tagName == 'TH' ||
    myHiddenTable.d ocument.all(i). tagName == 'TD') {
    myTableHTML += myHiddenTable.d ocument.all
    (i).innerText + '\t';
    }
    if (myHiddenTable. document.all(i) .tagName == 'TR') {
    if (myTableHTML.le ngth > 1)
    myTableHTML += '\n';
    }
    }

    // Put the HTML into the clipboard.
    window.clipboar dData.setData(' Text', myTableHTML);
    }

    [/CODE]
    I tried to run this code, but it seems not working in hidden table..I can't copy the content in hidden table but if I delete the code for hidden table, it works fine.

    I want to copy the content of this both table. Ho can i do that?
    Please help me out this...I will greatly appreciate ur help..

    Regards,
    froi
    Last edited by gits; Apr 11 '08, 08:01 AM. Reason: added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Instead of table.document. all use table.getElemen tsByTagName("th ") (tr, etc.) to get the tags or you could even use innerHTML.

    Comment

    • froilan03
      New Member
      • Apr 2008
      • 2

      #3
      Originally posted by acoder
      Instead of table.document. all use table.getElemen tsByTagName("th ") (tr, etc.) to get the tags or you could even use innerHTML.

      Hi,

      I want to insert a code for hiddenTable inside this for loop:

      [CODE=javascript]for (var i=0;i < myTable.documen t.all.length; i++) {
      if (myTable.docume nt.all(i).tagNa me == 'TH' ||
      myTable.documen t.all(i).tagNam e == 'TD') {
      myTableHTML += myTable.documen t.all
      (i).innerText + '\t';
      }
      if (myTable.docume nt.all(i).tagNa me == 'TR') {
      if (myTableHTML.le ngth > 1)
      myTableHTML += '\n';
      }
      }

      [/CODE]how can I do that? or what and where I put some code for hiddenTable?
      Would you please give me an example code or logic for hiddenTable.

      Thanks for your help..
      Last edited by acoder; Apr 14 '08, 09:28 AM. Reason: Added code tags

      Comment

      Working...