I want to save user input as a Javascript variable so I can use it on other pages of my site. How can I do that? Now the variable will be deleted if I go to the next page and I get the error "Uncaught ReferenceError: userInput is not defined"
Here is my code:
function test(){
const userInput = document.getElementById("naam").value;
window.location.href = "interactie1.html";
console.log(userInput);
}
document.getElementById("js--terminal--text").innerHTML = "";
typeText = (textToBeTyped) =>{
if(textToBeTyped != ""){
document.getElementById("js--terminal--text").innerHTML += textToBeTyped[0];
textToBeTyped.splice(0,1);
setTimeout(() => {
typeText(textToBeTyped);
},100);
}
}
typeText(Array.from("Hello this is "))
typeText(userInput);
<input class="naam__aanwezigheid__form" type="text" id="naam" placeholder="Type je naam" required>
<button onclick="test()">Submit</button>