I have an HTML input box
<input type="text" id="foo" value="bar">
I've attached a handler for the 'keyup' event, but if I retrieve the current value of the input box during the event handler, I get the value as it was, and not as it will be!
I've tried picking up 'keypress' and 'change' events, same problem.
I'm sure this is simple to solve, but at present I think the only solution is for me to use a short timeout to trigger some code a few milliseconds in the future!
Is there anyway to obtain the current value during those events?
EDIT: looks like I had a caching problem with my js file as I checked the same code later on and it worked just fine. I would delete the question, but not sure if that loses rep for the kind folk who posted ideas :)
Get the value of input type checkbox The DOM query was done using document. getElementById('_id_'), which queries the document for elements with a matching id attribute. An element's Id is unique. Finding elements by Id ensures that you will only get a single element back.
The onkeypress attribute fires when the user presses a key (on the keyboard). Tip: The order of events related to the onkeypress event: onkeydown.
Can you post your code? I'm not finding any issue with this. Tested on Firefox 3.01/safari 3.1.2 with:
function showMe(e) { // i am spammy! alert(e.value); } .... <input type="text" id="foo" value="bar" onkeyup="showMe(this)" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With