Add / remove table row. javascript

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2007
Posts: 9
Reputation: thenamenoonehas is an unknown quantity at this point 
Solved Threads: 0
thenamenoonehas thenamenoonehas is offline Offline
Newbie Poster

Add / remove table row. javascript

 
0
  #1
Aug 31st, 2008
Hi everyone,

Im looking for a simple function to add / remove a table row for my website. I have searched high and low for a script that does it... but no dice...

can anyone shoot me a link or post a snippet of code that would enable me to create an additional table row.

cheers
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Add / remove table row. javascript

 
0
  #2
Sep 1st, 2008
Please feel free to modify this code to match your needs. If you have any question regarding this code you can document.write('Me on my inbox'). lol! Have a good day...
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Some Title</titles>


  1. <script type="text/javascript">
  2. <!-- BEGIN HIDING
  3. function addRow()
  4. { /* A quick example on how to add and delete table rows. Enjoy coding! */
  5.  
  6. var _table = document.getElementById('table1').insertRow(0);
  7. var cell0 = _table.insertCell(0);
  8. var cell1 = _table.insertCell(1);
  9. cell0.innerHTML = 'New Cell1';
  10. cell1.innerHTML = 'New Cell2';
  11. }
  12. function removeRow(rows)
  13. { var _row = rows.parentElement.parentElement;
  14. document.getElementById('table1').deleteRow(_row.rowIndex);
  15. }
  16. // DONE HIDING -->
  17. </script>
  1. </head>
  2. <body>
  3. <table id="table1" border="1">
  4. <tr>
  5. <td>Row1 cell1</td>
  6. <td>Row1 cell2</td>
  7. </tr>
  8. <tr>
  9. <td>Row2 cell1</td>
  10. <td>Row2 cell2</td>
  11. </tr>
  12. <tr>
  13. <td>Row3 cell1</td>
  14. <td>Row3 cell2</td>
  15. </tr>
  16. </table>
  17. <br />
  18. <input type="button" onclick="addRow()" value="Add Row" />
  19. <input type="button" onclick="removeRow(this)" value="Del Row" />
  20.  
  21. </body>
  22. </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC