473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

append a HTML string to a Table

mickey0
142 100+
hi my code is this:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function myFunc () {
  3.     var s = "<tr><td><a href=\"http://www.google.com\">Hello</a></td></tr>";
  4.     var elem = document.getElementById("intro").insertRow(-1);  
  5.     //document.writeln(s);    
  6.     var linkText = document.createTextNode(s); //this cannot be a Text
  7.     elem.appendChild(linkText);
  8. }   
  9. </script>
  10.  <body onload="myFunc()">
  11.     <table  border="5" >       
  12.        <tbody id="intro">  </tbody>
  13.     </table>
  14. </body>
  15.  
I need to render the string s between tbody. Is there a solution, please?

Thanks.
Jan 22 '08 #1
3 2110
Delerna
1,134 Expert 1GB
will something like this do

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.    <head>
  3.       <script language="javascript">
  4.          var cnt=2;
  5.  
  6.          function AddRow()
  7.          {  
  8.             var table = document.getElementById("myTable");
  9.             if (!table) throw "Table not found";
  10.  
  11.             var row = table.insertRow(-1); //append at the end
  12.  
  13.             var cell1 = row.insertCell(-1);
  14.             var cell2 = row.insertCell(-1);
  15.             var cell3 = row.insertCell(-1);
  16.  
  17.             cell1.setAttribute('align','right');
  18.  
  19.             cell1.innerHTML = cnt;
  20.             cell2.innerHTML = 'test' + cnt.toString();;
  21.             cell3.innerHTML = 'test';
  22.  
  23.  
  24.             cnt++;
  25.          }
  26.  
  27.      function RemoveRow()
  28.      {  var table = document.getElementById("myTable");
  29.         table.deleteRow(-1);
  30.      }
  31.       </script>
  32.    </head>
  33.  
  34.    <body>
  35.       <table><tr>
  36.       <td><input type="button" onClick="AddRow();" value="Add Row"></td>
  37.       <td><input type="button" onClick="RemoveRow();" value="Remove Row"></td>
  38.       </tr></table>
  39.  
  40.       <table rules='none' cellspacing=0 frame='box' id="myTable">
  41.          <tr>
  42.             <td>1</td>
  43.             <td>sam</td>
  44.             <td>stephens</td>
  45.          </tr>
  46.       </table>
  47.  
  48.  
  49.  
  50. </body>
  51. </html>
  52.  
Jan 22 '08 #2
mickey0
142 100+
hello,
my problem isn't how insert a row in the table; my problem is append (i Say append because I found that innerHTML doens't work properly with IE) an element like
var s = "<tr><td><a href=\"http://www.google.com\">Hello</a></td></tr>";
If I create and ElementText, s will append as string; but I don't want it....and the id="intro" is on tbody....
Jan 22 '08 #3
acoder
16,027 Expert Mod 8TB
Why not use the DOM methods instead? You might find this link helpful.
Jan 23 '08 #4

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

Similar topics

3
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
4
by: Martin | last post by:
There is an Access table on the network. 15 users who do not have Access are connected to the network. Is there a way for each user to be able to enter one or more rows containing 3 or 4 columns to...
2
by: Danny | last post by:
I want to extract a subset of fields from one table into another the master table has many fields the subset has about half, but still many. Is there a way I can just append the master into the...
0
by: karinski | last post by:
Hi All, I have a split f/e - b/e setup on my database with RWOP queries on the front end. The code below gets a PO number(s), and vendor name from a multi choice list box on another form. It...
5
by: Michael C via AccessMonster.com | last post by:
Hello, I have a table that I am appending 3 seperate tables into. My main problem is that each time I append the data, it simply adds to the data already there. That might sound ok, except that...
5
by: solar | last post by:
I have copied a function that appends from table orders2 into table orders1 the row that has the value SubOrder = True in the table orders2. This function finds the highest ordered in the table...
1
by: socasteel21 via AccessMonster.com | last post by:
I have a spreadsheet that has 3 tabs each of the worksheets is setup exactly like a cooresponding table in Access. I created a button that should import each tab to a new table and then append...
4
by: dougmeece | last post by:
Morning Everyone... I have a table that needs to be append to and also updated. All the fields in the table are populated with data from the text boxes and combo boxes on a form. The Date...
3
by: lukethegooner | last post by:
I can't see the wood for the tree's here, I have some code set up to run through a bunch of delete queries, re-append fresh information to local DB tables then run a report. But in the code below...
4
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.