Dynamic Table Creation

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

Join Date: Mar 2008
Posts: 52
Reputation: clueless101 is an unknown quantity at this point 
Solved Threads: 0
clueless101 clueless101 is offline Offline
Junior Poster in Training

Dynamic Table Creation

 
0
  #1
Nov 18th, 2008
Once my dynamic table is populated with names entered by user, it should no longer include the initial text: Your name list is empty.

Can anyone help me with this final code?
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>My Dynamic Table</title>
  5. <script type ="text/javascript">
  6.  
  7. //This fx adds a new row to the name table and inserts 1st cell with text box and 2nd cell with remove button
  8. function addRow(item1) {
  9. var newRow = document.getElementById("nameTable").insertRow();
  10. var newCell = newRow.insertCell();
  11. newCell.innerHTML = "<input type='text' name='tableList' value='" + item1 + "'>&nbsp;&nbsp;<input type='button' value='Remove Name' onclick='removeRow(this);'/>";
  12. }
  13. //This fx deletes unwanted name lines
  14. function removeRow(src) {
  15. if (document.getElementById("nameTable").rows.length >1) {
  16. var dRow = src.parentElement.parentElement;
  17. }else {
  18. document.getElement.ById("nameTable").rows[0].innerHTML = "<td>Your name list is empty</td>";
  19. }
  20. //once the row reference is obtained, delete it passing in its rowIndex
  21. document.getElementById("nameTable").deleteRow(dRow.rowIndex);
  22. }
  23. </script>
  24. </head>
  25. <body>
  26. <form action="get">
  27. <p><strong>Enter name to be included in Name List:</strong></p>
  28. <input type="text" name="input"/><input type="button" value="Add Name" onclick="addRow(this.form.input.value)" />
  29. </form>
  30. <form>
  31. <h1>Name List</h1>
  32. <table id="nameTable" border="5">
  33. <tr>
  34. <td>Your name list is empty
  35. </td>
  36. </tr>
  37. </form>
  38. </table>
  39. </form>
  40. </body>
  41. </html>
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 52
Reputation: clueless101 is an unknown quantity at this point 
Solved Threads: 0
clueless101 clueless101 is offline Offline
Junior Poster in Training

Re: Dynamic Table Creation

 
0
  #2
Nov 19th, 2008
Never mind - added a few variables and an if clause and solved the problem.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 52
Reputation: clueless101 is an unknown quantity at this point 
Solved Threads: 0
clueless101 clueless101 is offline Offline
Junior Poster in Training

Re: Dynamic Table Creation

 
0
  #3
Nov 19th, 2008
Never mind - added a few variables and an if clause. Problem Solved!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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