Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

70
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda