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

62
Views
Add the form when click the reply button in the comments section

I designed a comment section with a reply. I want a comment form to be created under the same comment when the user clicks on the reply button. I wrote this myself, but when I click on the reply button, the form is created only for the first comment.

function addtextbox() {
  // Create a form dynamically.
  var form = document.createElement("form");
  
  form.setAttribute("method", "post");
  form.setAttribute("action", "submit.php");

  // Create an input element for replyText.
  var ID = document.createElement("input");
  
  ID.setAttribute("type", "text");
  ID.setAttribute("name", "body");
  ID.setAttribute("placeholder", "Your Comment");
  form.append(ID);
  document.getElementsByClassName('formbox')[0].appendChild(form);
}
<button onclick="addtextbox()">reply</button>
<div class="formbox"></div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

there is a lot of way, but this is the simplest. good luck ;)

        const replayButtons = document.querySelectorAll('.replay');
        
        replayButtons.forEach(item => {
            item.addEventListener('click', () => {
                item.parentElement.insertAdjacentHTML('beforeend', `
                    <input type="text" placeholder="write your replay" />
                `);
            });
        })
    <div>
        <h1>Post1</h1>
        <p>Lorem ipsum dolor sit.</p>
        <br>
        <button class="replay">Replay</button>
        <br>
    </div>
    <div>
        <h1>Post2</h1>
        <p>Lorem ipsum dolor sit.</p>
        <br>
        <button class="replay">Replay</button>
        <br>
    </div>
    <div>
        <h1>Post3</h1>
        <p>Lorem ipsum dolor sit.</p>
        <br>
        <button class="replay">Replay</button>
        <br>
    </div>

about 4 years ago · Juan Pablo Isaza 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!