I have this code used to collect data from a form using a textarea. This form also has a button to generate more textarea.
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit(){
return "Ha intentado salir de esta pagina. Si ha realizado algun cambio en los campos sin hacer clic en el boton Guardar, los cambios se perderan. Seguro que desea salir de esta pagina? ";
}
var table_inputs = 0;
function addTextarea(id, name) {
var table = document.getElementById(id);
var row = table.insertRow(2);
var cell = row.insertCell(0);
var input = document.createElement("textarea");
table_inputs++;
input.rows = "4";
input.cols = "170";
input.name = name + table_inputs;
input.id = id + table_inputs;
var campo = document.createElement("input");
campo.type = "button";
campo.value = "Borrar";
campo.onclick = function () {
var fila = this.parentNode.parentNode;
var tbody = table.getElementsByTagName("tbody")[0];
tbody.removeChild(fila);
}
cell.appendChild(input);
cell.appendChild(campo);
}
function vaciar_campo(input1) {
input1.value = "";
}
</script>
</HEAD>
<BODY>
<form name="formulario" id="formulario" action="creador.php" method="post" width="30%">
<table id="tablafecha" border="3" width="100%">
<tr>
<td><h1>Fecha y número</h1>
</td>
</tr>
<tr>
<td>Fecha: <input type="text" name="fecha" id="fecha"><br>
Número: <input type="number" name="numero" id="numero">
</td>
</tr>
</table>
<table id="tesisTable" border="3" width="100%">
<tr>
<td><h1>TESIS DOCTORAL</h1>
</td>
</tr>
<tr>
<td>
<textarea name="tesis" id="tesis" rows="4" cols="170"></textarea>
<button onclick="addTextarea('tesisTable', 'tesis')" type="button" name="tesis2" id="tesis2">Añadir</button>
</td>
</tr>
</table>
<center>
<input type="submit" value="Enviar">
</center>
</form>
In another code, I have how they are collected and how I represent them.
<script type="text/javascript">
var datos ="<?php foreach( $tesis as $key => $value ): ?><?php echo $value; ?><?php endforeach; ?>";
var datos2 ="<?php foreach( $subvenciones as $key => $value ): ?><?php echo $value; ?><?php endforeach; ?>";
var datos3 ="<?php foreach( $otrainfo as $key => $value ): ?><?php echo $value; ?></ul><?php endforeach; ?>";
var datos4 ="<?php foreach( $actualidad as $key => $value ): ?><?php echo $value; ?><?php endforeach; ?>";
How would you make the new textarea that I generate with each button create an array independent of the first one?