Adding rows to a table by javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yuvaly
    New Member
    • Feb 2008
    • 6

    Adding rows to a table by javascript

    Hi

    I want to Query a database using AJAx and display the results in the middle rows of an existing table. right now the server builds rows and return them to the main page, but I don't know how to insert them to the right spot.
    basically, I look for a function he inserts a string before /after some row in the table .

    in the pad I have:
    <table>
    <tr><td>Heade r</td></tr>
    <tr><td>foote r</td></tr></table

    I have a string : "<tr><td>Re sult 1</td></tr>" I want to insert between the Header and the footer using Javascript. How can I do it? [I get this string from the server].

    Thanks
    Yuval
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    This example may help you.

    Comment

    • yuvaly
      New Member
      • Feb 2008
      • 6

      #3
      Thank you, but this example uses Insert Row, that means I have to read the content of the response I get from the server to know whar rows/collums to insert, when in the server they already formatted it so I can just insert it...I want to insert a whole string [that represents several rows] into the table between the two rows.

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by yuvaly
        Thank you, but this example uses Insert Row, that means I have to read the content of the response I get from the server to know whar rows/collums to insert, when in the server they already formatted it so I can just insert it...I want to insert a whole string [that represents several rows] into the table between the two rows.
        That is not possible I guess. Instead sending the whole string from the server, send tokenized string (with all the fields and rows saperated by token eg. a pipe |). And on the front, split() it and add the rows at required positions.

        Comment

        • iam_clint
          Recognized Expert Top Contributor
          • Jul 2006
          • 1207

          #5
          you can do table.innerHTML = table.innerHTML +MyOtherVar;

          However this is not standard and may not work on some browsers properly.

          Comment

          Working...