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

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

P: 2
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:

Expand|Select|Wrap|Line Numbers
  1. function copyTable(tableNumber) {
  2.  
  3.     // Get the table frame
  4.     var tableIFrame = eval("generatedFrame" + tableNumber);    
  5.     // Get the table
  6.     var tableOnPage = tableIFrame.document.getElementById("table" +  
  7.                                            tableNumber);
  8.     // Clone this table, so that we can remove the links without changing
  9.                    the page
  10.     var myTable = tableOnPage.cloneNode(true);
  11.  
  12.     var hiddenTableOnPage = document.getElementById
  13.                                                       ("tableIDHiddenField" + tableNumber);
  14.  
  15.     var myHiddenTable = hiddenTableOnPage.cloneNode(true);
  16.  
  17.     var myTableHTML = "";
  18.  
  19.     // Run through stripping out links
  20.     for (var i=0;i < myTable.document.all.length; i++) {
  21.         if (myTable.document.all(i).tagName == 'A') {
  22.             myTable.document.all(i).removeNode(false);
  23.         }    
  24.  
  25.     }
  26.  
  27.     // Get the HTML for the table
  28.     for (var i=0;i < myTable.document.all.length; i++) {        
  29.         if (myTable.document.all(i).tagName == 'TH' ||
  30.             myTable.document.all(i).tagName == 'TD') {
  31.             myTableHTML += myTable.document.all
  32.                                                  (i).innerText + '\t';
  33.         }
  34.         if (myTable.document.all(i).tagName == 'TR') {
  35.             if (myTableHTML.length > 1) 
  36.                 myTableHTML += '\n';
  37.         }
  38.     }
  39.  
  40.                 // Run through stripping out links
  41.     for (var i=0;i < myHiddenTable.document.all.length; i++) {
  42.         if (myHiddenTable.document.all(i).tagName == 'A') {
  43.         myHiddenTable.document.all(i).removeNode(false);
  44.         }
  45.  
  46.     }
  47.  
  48.                 // Get the HTML for the hidden table
  49.     for (var i=0;i < myHiddenTable.document.all.length; i++) {                    
  50.         if (myHiddenTable.document.all(i).tagName == 'TH' ||
  51.         myHiddenTable.document.all(i).tagName == 'TD') {
  52.         myTableHTML += myHiddenTable.document.all
  53.                                 (i).innerText + '\t';
  54.         }
  55.         if (myHiddenTable.document.all(i).tagName == 'TR') {
  56.             if (myTableHTML.length > 1) 
  57.                 myTableHTML += '\n';
  58.         }        
  59.     }
  60.  
  61.     // Put the HTML into the clipboard.
  62.     window.clipboardData.setData('Text', myTableHTML);
  63. }
  64.  
  65.  
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
Apr 11 '08 #1
Share this Question
Share on Google+
2 Replies


acoder
Expert Mod 15k+
P: 16,027
Instead of table.document.all use table.getElementsByTagName("th") (tr, etc.) to get the tags or you could even use innerHTML.
Apr 13 '08 #2

P: 2
Instead of table.document.all use table.getElementsByTagName("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:

Expand|Select|Wrap|Line Numbers
  1. for (var i=0;i < myTable.document.all.length; i++) {        
  2.         if (myTable.document.all(i).tagName == 'TH' ||
  3.             myTable.document.all(i).tagName == 'TD') {
  4.             myTableHTML += myTable.document.all
  5.                                                  (i).innerText + '\t';
  6.         }
  7.         if (myTable.document.all(i).tagName == 'TR') {
  8.             if (myTableHTML.length > 1) 
  9.                 myTableHTML += '\n';
  10.         }
  11.     }
  12.  
  13.  
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..
Apr 14 '08 #3

Post your reply

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