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

237
Visualizações
How to display multiple words from the same submission form?

I am trying to make a submission form that can be used multiple times, which displays the words that are submitted next to each other. So far I have been able to do the submission form and when the submit button is pressed, the word is displayed, but when the submission form is filled with another word and re-submitted, it takes over the previous word that was displayed. Here is my code:

function showTag(){
    document.getElementById('display').innerHTML = 
          document.getElementById("user_input").value;
}
<form>
    <input type="text" name="message" id="user_input">
</form>
<input type="submit" onclick="showTag()">
<p><span class="tag is-info" style="background-color:#33475b;color:white;" id='display'></span></p>

I have looked around but all I have been able to find are "multiple submit buttons" solutions, which is not what I am looking for. Any help would be very appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For that you need to have a intermediary variable that can store all the values:

    const arr = [];

    function showTag() {
        arr.push(document.getElementById("user_input").value)
        document.getElementById('display').innerHTML = arr.join(' ')
    }
<form>
    <input type="text" name="message" id="user_input">
</form>
<input type="submit" onclick="showTag()">
<p><span class="tag is-info" style="background-color:#33475b;color:white;" id='display'></span></p>

Edit: For each submission from the user become a new element, you will still need the array to store the data from the user, but instead of joining the array, you must create a new element with the last item from the array:

    const arr = [];

    function showTag(e) {

        arr.push(document.getElementById("user_input").value)
        phrase = document.createElement('p');
        phrase.innerHTML = arr.at(-1);
        document.getElementById('phrases').appendChild(phrase);


    }
    p {
        width: fit-content;
        background-color: #33475b;
        color: white;
    }
<form>
    <input type="text" name="message" id="user_input">
</form>
<input type="submit" onclick="showTag()">
<div id='phrases'></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