Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   HTML, Javascript y otros (https://www.clubdelphi.com/foros/forumdisplay.php?f=38)
-   -   Crear input dinámicamente que cree otros elementos html (https://www.clubdelphi.com/foros/showthread.php?t=85692)

jandroruiz 18-04-2014 13:24:11

Crear input dinámicamente que cree otros elementos html
 
Hola, a ver si me podéis ayudar.

Tengo este código:

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


La franja horaria es GMT +2. Ahora son las 11:18:22.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi