PDA

Ver la Versión Completa : Crear input dinámicamente que cree otros elementos html


jandroruiz
18-04-2014, 13:24:11
Hola, a ver si me podéis ayudar.

Tengo este código:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Añadir elementos</title>
<script type="text/javascript">

function creaCaja()
{
var x1 = document.getElementById('caja1').checked;

if(x1)
{
creaCaja2();
}
}
function creaCaja2()
{
document.getElementById('espacio1').innerHTML = '<label>CAJA 2</label>
<input type="checkbox" name="nueva_caja" id=caja2/><button onclick="creaCaja2()">Dale2</button>';

¿QUÉ CÓDIGO INCLUIR AQUÍ PARA QUE VAYA A LA FUNCIÓN creaElementos2?
}
function creaElementos2()
{
document.getElementById('espacio2').innerHTML = '<label>CAJA 3</label>
<input type="checkbox" name="nueva_caja2" id=caja3/><button onclick="creaCaja3()">Dale3</button>';
}
</script>
</head>
<body>
<label>CAJA 1</label><input name="caja1" type="checkbox" id="caja1" />
<button onclick="creaCaja()">Dale</button>
<div id="espacio1"></div>
<div id="espacio2"></div>
</body>
</html>


Al iniciarse la página se muestra una checkbox y un botón. Si se pone la checkbox en "checked" y se pulsa el botón aparece otra checkbox y otro botón. Lo que quiero saber es cómo hacer que una vez puesta la segunda checkbox en "checked" y pulsado el segundo botón se cree otro elemento, sea otra checkbox u otra cosa.

¿Me podéis orientar un poquito?

Muchas gracias