There is a dynamic table. The task is to ensure that after filling in the table with information on the button, all the data goes to the table in the database which should be created on the fly.

HTML:

<p><strong>Имя таблицы</strong></p> <p><input maxlength="25" size="40" ></p> <table> <tbody id="contacts"> <tr> <td colspan="3"><a href="#" onclick="addContact (); return false">Добавьте контакт</a></td> </tr> <tr> <td width = 20 ></td> <td>Имя </td> <td>Email</td> <td>text</td> </tr> </tbody> </table> 

Js

  function addContact () { var tb = document.getElementById ('contacts'), ro = tb.insertRow (-1), ce = ro.insertCell (-1); if (tb.rows.length == 2) ce.innerHTML = '&nbsp;'; else { var im = document.createElement ('img'); im.src = 'del.jpg'; im.onclick = function () {tb.deleteRow (this.parentNode.parentNode.rowIndex)} ce.appendChild (im); } NUM = (!self.NUM) ? 1 : ++NUM; var ce = ro.insertCell (-1), inp = document.createElement ('input'); inp.name = 'name' + NUM; ce.appendChild (inp); var ce = ro.insertCell (-1), inp = document.createElement ('input'); inp .name = 'email' + NUM; ce.appendChild (inp); var ce = ro.insertCell (-1), inp = document.createElement ('input'); inp.name = 'text' + NUM; ce.appendChild (inp); } 
  • I wonder why every time to create a new table? If you add a contact each time, judging by the code. - Valery Gorbunov
  • This is just a template, in fact, pages with unique content will be generated - Pavel
  • as an option, you can wrap the entire table in a form and make fields with input or textrea, and then submit the form and send it to the php file where you intercept it and send it to the database - Broouzer King
  • But how to do it?! And so the input - Paul

0