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

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

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 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!