This is a part of my code:
button.addEventListener("keydown", function(e) {
var theVal = document.getElementById('theInput').value;
The problem is that the thing i’m copying into “theVal” is the thing i’m putting my key
down to. so here button is the same as theInput. so when a user enters:
hey
theVal actually holds:
he
so always the last key that was pressed isn’t captured. How do i overcome this?
You should add event listener to
theInputinstead.Also try to do the same thing in
OnkeyUpevent.