Javascript - get value from textbox at every keypress
alert, javascript, jquery, onchange, textbox
Solution
`keypress` happens before the change, yes. `keyup` happens after. Listen to that instead.
Problem
I have a textbox and I want to use the data in it every time something is entered; letter by letter. What is happening is that when a value is entered, the Javascript is being executed before the value is actually put into the textbox, meaning that it always lags one character behind. ``` $(document).ready( function() { $('#test').keypress( function() { var value = document.getElementById('test').value; alert(value); }); }) <input id="test" type="text" /> ``` Here's whats happening: ``` input alert w "" e "w" a "we" l "wea" t "weal" h "wealt" ``` Whereas I want it to happen dynamically; i.e. when I enter "w" I want the alert to contain "w" immediately after.