I attempted to display the content of the input box in a message div simultaneously, however, the output always seems to be one step behind.
function showWhatsWritten(){
var tempText;
tempText = document.getElementById("text").value;
document.getElementById("message").innerHTML = tempText;
}
<input id="text" type="text" onkeydown="showWhatsWritten()"/>
<div id="message"></div>
The output consistently appears as follows:
input: 123456
output: 12345 (missing 6)
input: abcde
output: abcd (missing e)
Any assistance on resolving this issue would be greatly appreciated! Thank you!