I have set up a web form using HTML to collect user data. Once the user submits the form, I am using JavaScript to store this data in an array. Here is my current code:
function saveData(){
var userName = document.getElementById('myName').value;
var dataArray = ["dataOne"];
dataArray.push("dataTwo");
dataArray.push("dataThree");
dataArray.push(userName);
}
THE PROBLEM: The data entered by the user gets saved at index 3 in the array, whereas I want each new user submission to be stored at the next available index (e.g., index 4, 5, and so on). Currently, every user input overrides the previous one. For example:
User 1 Submits:
[dataOne, dataTwo, dataThree, User 1 Input]
If User 2 Submits:
[dataOne, dataTwo, dataThree, User 2 Input]
As you can see, User 1's input has been replaced by User 2's input. I need each user's data to be stored separately.
If anyone has a solution, I would greatly appreciate it. Thank you!