dimanche 15 mars 2020

In JavaScript, once the user submit a value, how do I keep input value printed?

I am trying to accomplish the following tasks shown in the image attached. As you can see, there are 5 submissions, how can I accomplish to keep all 5 submissions printed on the page? So far, I can only keep 1 submission, but as soon as I submit another one, it replaces it. This is my code.

var i = ",";
var listItem = " ";
var count = 0;

document.getElementById("sButton").addEventListener("click", processInput, false);

function processInput() {

    if (listItem = document.getElementById("inputText").value) {

        var inputValue = document.getElementById("inputText").value;
        document.getElementById("label").innerHTML = inputValue + ",";
    }

    else {
        (document.getElementById("label").innerHTML = " ");
    }

    if (count++ == 4) {            
        document.getElementById("message").innerHTML = "Gracias por sus 
                     sugerencias."
    }
}```

[Here, right below the textbox, it's showing 5 items/inputs that were submitted. How do I keep those and not lose them when another input is submitted?][1][1]: https://i.stack.imgur.com/4zRuT.png

Aucun commentaire:

Enregistrer un commentaire