Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!