0

Hy, I have read many discussion on this argument but I just can't find a solution. I have table inside a form, the first rows of this table are displayed by a php script, I won't the user to be able to add a row to the table so that he can insert a new set of values. the problem is that this new rows that I insert don't get submitted. here is the php code

    <form method="post">
<table name="elencoAltriContatti" id="elencoAltriContatti">
<button type="button" class="btn primary success" onClick="showNewContatti();" name="nuovo">NUOVO</button>
<tr>
<td><p><strong>Nome</strong></p></td>
<td><p><strong>Qualifica</strong></p></td>
<td><p><strong>Email</strong></p></td>
<td><p><strong>Telefono</strong></p></td>
<td></td>
</tr>
<?php 
  echo "<tr>";
  echo "<td><p><input type=\"text\" id=\"nome\" name=\"NOME[]\" value=\"".$row['NOME']."\" class=\"input-text3\" onchange=\"selectCheckbox('".$i."')\"></p></td>";
  echo "<td><p><input type=\"text\" id=\"qualifica\" name=\"QUALIFICA[]\" value=\"".$row['QUALIFICA']."\" class=\"input-text3\" onchange=\"selectCheckbox('".$i."')\"></p></td>";
  echo "<td><p><input type=\"text\" id=\"email\" name=\"EMAIL[]\" value=\"".$row['EMAIL']."\" class=\"input-text3\" onchange=\"selectCheckbox('".$i."')\"> </p></td>";
  echo "<td><p><input type=\"text\" id=\"telefono\" name=\"TELEFONO[]\" value=\"".$row['TELEFONO']."\" class=\"input-text3\" onchange=\"selectCheckbox('".$i."')\"></p></td>";
  echo "<td><input id=\"".$i."\" name=\"CHECKBOX[]\" type=\"checkbox\" value=\"\" style=\"float:right\"></td>";
  echo "</tr>";
?>

</table>
<div class="control-group">
    <div class="controls">
     <button type="reset" name="reset"  class="btn info">CANCELLA</button>
     <button type="submit" name="submit"  class="btn info" >SALVA</button>
    </div>
  </div>

</form>

wich works just fine, and here is the javascript function I use

function showNewContatti(){
  var table = document.getElementById('elencoAltriContatti');
  var lastRow = table.rows.length;
  var row=table.insertRow(lastRow);
  var nome=row.insertCell(0);
  var qualifica=row.insertCell(1);
  var email=row.insertCell(2);
  var telefono=row.insertCell(3);
  var checkbox=row.insertCell(4);
  nome.innerHTML="<p><input type=\"text\" id=\"nome\" name=\"NOME[]\" class=\"input-text3\" onchange=\"selectCheckbox('"+lastRow+"')\"></p>";
  qualifica.innerHTML="<p><input type=\"text\" id=\"qualifica\" name=\"QUALIFICA[]\" class=\"input-text3\" onchange=\"selectCheckbox("+lastRow+")\"></p>";
  email.innerHTML="<p><input type=\"text\" id=\"email\" name=\"EMAIL[]\" class=\"input-text3\" onchange=\"selectCheckbox("+lastRow+")\"></p>";
  telefono.innerHTML="<p><input type=\"text\" id=\"telefono\" name=\"TELEFONO[]\" class=\"input-text3\" onchange=\"selectCheckbox("+lastRow+")\"></p>";
  checkbox.innerHTML="<input type=\"checkbox\" id=\""+lastRow+"\" name=\"CHECKBOX[]\" style=\"float:right\">";}

new rows added with this function just don't get submitted, do you have some ideas? thank's for the help

EDIT: I have changed my javascript function, now it looks like this:

 var table = document.getElementById('elencoAltriContatti');
  var lastRow = table.rows.length;
  var Iterator=lastRow; 
  var row=table.insertRow(lastRow);

  var nome = row.insertCell(0);
  var cell = document.createElement('input');
  cell.type = 'text';
  cell.name = 'nome' + Iterator;
  cell.id = 'nome' + Iterator;
  cell.className= 'input-text3';
  cell.onchange= function(){
    selectCheckbox(Iterator);
 };
  nome.appendChild(cell);

but I still have the same problem, what else can I do?

4

1 回答 1

0

在您的 innerHTML 行中,您传递的 name 属性与原始行中的相同。表单元素以名称=值对的形式发布。两个表单元素不能具有相同的名称。

要在 javascript 中添加表单元素,您应该动态构建 name 属性:

i=1;
name='nome'+i;
html="<input type='text' name='" + name + "' />";
i++; //etc...
于 2013-11-06T00:19:00.377 回答