Javascript TextBox input value is not updating -


my requirement on keypress need value of particular textbox. problem when press first letter getting blank output. on second keypress getting first letter have entered in textbox. form here on getting 1 step delay. missing anything.

 <script>      document.addeventlistener('keypress',function(e){            var keycode = e.keycode || e.which;            if(document.activeelement.id == 'k_id_234'){                 console.log(document.getelementbyid('k_id_234').value);             }      });    </script> <input type="text" id="k_id_234">  text box : h    console :     // empty text box :   console : h   //only first letter ....  ......  

use keyup event instead

document.addeventlistener('keyup', function (e) {     var keycode = e.keycode || e.which;     if (document.activeelement.id == 'k_id_234') {         console.log(document.getelementbyid('k_id_234').value);      } }); 

demo: fiddle


another option input event


Comments