I want to display text in aspan
.
The text comes from the user who puts it into aninput
field.
This is the HTML with the input field:
This is the HTML for the span
with the ID
<div class="box box3">
Some copy on the website <span id='text'>this shiould be changed </span>some copy on the website
</div>
This is the JS
let a = document.getElementById("geld");
a.addEventListener('input', () => console.log(a.value))
//a = parseInt(a, 10);
b = a.toString();
document.getElementById('text').innerHTML = b;
This code above leads to the message:
[object HTMLInputElement]
Itβs not displaying the text, the user puts into the input fiel.
Than I tried:
let a = document.getElementById("geld");
a.addEventListener('input', () => console.log(a.value))
a = parseInt(a, 10);
document.getElementById('text').innerHTML = a;
(I converted the input into a number with parsInt.)
When executing this code, I get.
βNAN
β in my HTML.
Could anyone explain whats happening and what I need to do, to get text displayed in my span?
Best,
S.