As it were, so I have structured everything: Here is the website with fixed textarea and those that can be generated.
<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 table1_inputs=0;
function myCreateFunction()
{
var table = document.getElementById("myTable");
var row = table.insertRow(2);
var cell2 = row.insertCell(0);
var input1= document.createElement("textarea");
input1.rows="4";
input1.cols="170";
table1_inputs++;
input1.name= 'name1'+table1_inputs;
input1.id = 'id1'+table1_inputs;
var campo4 = document.createElement("input");
campo4.type = "button";
campo4.value = "Borrar";
campo4.onclick = function ()
{
var fila = this.parentNode.parentNode;
var tbody = table.getElementsByTagName("tbody")[0];
tbody.removeChild(fila);
}
cell2.appendChild(input1);
cell2.appendChild(campo4);
}
function vaciar_campo(input1)
{
input1.value = "";
}
var table2_inputs=0;
function myCreateFunction2()
{
var table = document.getElementById("myTable2");
var row = table.insertRow(2);
var cell2 = row.insertCell(0);
var input2 = document.createElement("textarea");
input2.rows="4";
input2.cols="170";
table2_inputs++;
input2.name = 'name2'+table2_inputs;
input2.id = 'id2'+table2_inputs;
var campo4 = document.createElement("input");
campo4.type = "button";
campo4.value = "Borrar";
campo4.onclick = function ()
{
var fila = this.parentNode.parentNode;
var tbody = table.getElementsByTagName("tbody")[0];
tbody.removeChild(fila);
}
cell2.appendChild(input2);
cell2.appendChild(campo4);
}
function vaciar_campo(input2)
{
input2.value = "";
}
var table3_inputs=0;
function myCreateFunction3()
{
var table = document.getElementById("myTable3");
var row = table.insertRow(2);
var cell2 = row.insertCell(0);
var input3 = document.createElement("textarea");
input3.rows="4";
input3.cols="170";
table3_inputs++;
input3.name = 'name3'+table3_inputs;
input3.id = 'id3'+table3_inputs;
var campo4 = document.createElement("input");
campo4.type = "button";
campo4.value = "Borrar";
campo4.onclick = function ()
{
var fila = this.parentNode.parentNode;
var tbody = table.getElementsByTagName("tbody")[0];
tbody.removeChild(fila);
}
cell2.appendChild(input3);
cell2.appendChild(campo4);
}
function vaciar_campo(input3)
{
input.value = "";
}
var table4_inputs=0;
function myCreateFunction4()
{
var table = document.getElementById("myTable4");
var row = table.insertRow(2);
var cell2 = row.insertCell(0);
var input4 = document.createElement("textarea");
input4.rows="4";
input4.cols="170";
table4_inputs++;
input4.name = 'name4'+table4_inputs;
input4.id = 'id4'+table4_inputs;
var campo4 = document.createElement("input");
campo4.type = "button";
campo4.value = "Borrar";
campo4.onclick = function ()
{
var fila = this.parentNode.parentNode;
var tbody = table.getElementsByTagName("tbody")[0];
tbody.removeChild(fila);
}
cell2.appendChild(input4);
cell2.appendChild(campo4);
}
function vaciar_campo(input4)
{
input.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="myTable" 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="myCreateFunction()" type="button" name="Tesis2" id="Tesis2">
Añadir
</button>
</td>
</tr>
</table>
<table id="myTable2" border="3" width="100%">
<tr>
<td>
<h1>
Subvenciones
</h1>
</td>
</tr>
<tr>
<td>
<textarea name="Subvenciones" id="Subvenciones" rows="4" cols="170"></textarea>
<button onclick="myCreateFunction2()" type="button" name="Subvenciones2" id="Subvenciones2">
Añadir
</button>
</td>
</tr>
</table>
<table id="myTable3" border="3" width="100%">
<tr>
<td>
<h1>
Otra informacion
</h1>
</td>
</tr>
<tr>
<td>
<textarea name="Otrainfo" id="Otrainfo" rows="4" cols="170"></textarea>
<button onclick="myCreateFunction3()" type="button" name="Otrainfo2" id="Otrainfo2">
Añadir
</button>
</td>
</tr>
</table>
<table id="myTable4" border="3" width="100%">
<tr>
<td>
<h1>
Actualidad
</h1>
</td>
</tr>
<tr>
<td>
<textarea name="Actualidad" id="Actualidad" rows="4" cols="170"></textarea>
<button onclick="myCreateFunction4()" type="button" name="actualidad2" id="actualidad2">
Añadir
</button>
</td>
</tr>
</table>
<br>
<br>
<br>
<center>
<input type="submit" value="Enviar">
</center>
</form>
This is the code of the page that contains the content of the textarea (according to what you have explained to me).
<?php var_dump( $_POST );
$post = [];
if( !empty( $_POST ) ) {
$post = $_POST;
}
?>
var datos ="<?php foreach( $post as $key => $value ): ?><?php echo $value; ?><?php endforeach; ?>";
var datos2 ="<?php echo $_POST['Subvenciones']; ?>";
var datos3 ="<?php echo $_POST['Otrainfo']; ?>";
var datos4 ="<?php echo $_POST['Actualidad']; ?>";
var fecha ="<?php echo $_POST['fecha']; ?>";
var numero ="<?php echo $_POST['numero']; ?>";
var ventanaHTML = window.open("about:blank", "_blank");
ventanaHTML.document.writeln(Aquí va una página web la cual posee estilos y le inserto en sus correspondientes lugares, donde quiero que aparezca el contenido que he recogido)
The result within the web page would be:
Doctoral thesis
Grants
What problems occur to me? The information I collect is repeated in both Thesis and Grants. More li than they should be created, taking into account that what is generated by javascript.
EDITED 3
And if for example you want the created array not to be combined with the first of each section, how would you do it? For example, the field already created is thesis but the array I want it to be with the id, name otesis. I've been testing and it's not coming out.