I'm making art web project where I wan't to replace user inputed text to my own phrases in infnity.
Similar way like in game "Emily is away", but that will be only one phrase repeat in infinity.
Something like this: "text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text"
When user will be typing, the result will be always the same phrase.
My code looks this way:
function myFunction() {
result.innerHTML = "TEXT";
}
<input type="text" onkeydown="myFunction()">
<div id="result"></div>
I will be really glad for help.
CodePudding user response:
Is this what you mean? It will append the string to the existing output, rather than replacing it:
function myFunction() {
result.innerHTML = "TEXT ";
}
<input type="text" onkeydown="myFunction()">
<div id="result"></div>
CodePudding user response:
let myInput = document.querySelectorAll('input');
myInput.forEach(input => {
input.addEventListener('keydown', function() {
result.innerHTML = "TEXT ";
});
})
<input type="text">
<div id="result"></div>
