Código HTML :
<html>
<head>
<title>Crear Campo de texto</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
[js:1:d17519a7e3]
<script type="text/javascript">
icremento =0;
function crear(obj) {
icremento++;
field = document.getElementById('field');
contenedor = document.createElement('div');
contenedor.id = 'div'+icremento;
field.appendChild(contenedor);
boton = document.createElement('input');
boton.type = 'text';
boton.name = 'text'+'[]';
contenedor.appendChild(boton);
boton = document.createElement('input');
boton.type = 'button';
boton.value = 'Borrar';
boton.name = 'div'+icremento;
boton.onclick = function () {borrar(this.name)} //aqui llamamos a la funcion borrar
contenedor.appendChild(boton);
return contenedor.id;
}
function borrar(obj) {//aqui la ejecutamos
field = document.getElementById('field');
field.removeChild(document.getElementById(obj));
}
</script>
[/js:1:d17519a7e3]
</head>
<body>
<form name="form1" method="POST" action="validar5.php">
<fieldset id="field">
<p>
<input type="button" value="Crear caja de texto" onClick="crear(this)">
<input name="send" type="submit" value="Enviar" onClick="enviar(this)" id="send">
</p>
</fieldset>
</form>
Para leer las id's enviadas por POST me recomendaron:
Código PHP :
<?php echo "<pre>"; print_r($_POST); echo "</pre>"; $_POST=array(); $camp1=$_POST[0]; echo "$camp1"; ?>
i obtengo lo siguiente como resultado:
Array
(
[send] => Enviar
[text] => Array
(
[0] => campo1
[1] => campo2
[2] => campo3
)
)
Notice: Undefined offset: 0
que hago???
