Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
onchange element.appendChild again and again
<p class="label">
  <form id="links">
    <input type="text" class="insert" name="input" onchange="createLink()">
    <br>
  </form>
</p>
</div>
<script>
 function createLink() {
   var newline = document.createElement("br");
   var input = document.createElement("input");
   input.type = "text";
   input.name = "input";
   input.onchange = "createLink()";
   var element = document.getElementById("links");
   element.appendChild(newline);
   element.appendChild(input);
 }

</script>



I tried to repeat create a new input field again from the new input field, but its only possible from my first input field. Why? And whats the best solution

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

Use this code. I hope this code work you mean )

<p class="label">
      <form id="links">
          <input type="text" class="insert" name="input" onchange="createLink()"><br>
      </form>
</p>

<script>
    var element = document.getElementById("links");
    
    function createLink(){
      var newline = document.createElement("br");
      var input = document.createElement("input");
      input.type = "text";
      input.name = "input";
      input.addEventListener('change', createLink)

      element.appendChild(newline);
      element.appendChild(input);
    }
</script>
about 4 years ago · Santiago Gelvez Denunciar

0

Your Implementation is a little bit off the mark.Instead of passing the createLink as string. pass it as arrow function, as shown below:

<p class="label">
  <form id="links">
    <input type="text" class="insert" name="input" onchange="createLink()">
    <br>
  </form>
</p>
</div>
<script>
 function createLink() {
   var newline = document.createElement("br");
   var input = document.createElement("input");
   input.type = "text";
   input.name = "input";
   
   input.onchange = ()=> createLink();
   var element = document.getElementById("links");
   element.appendChild(newline);
   element.appendChild(input);
 }

</script>
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda