Possible Duplicate:
jQuery get input value after keypress
I'm trying to get an input text
value on jQuery
.keypress()
function. I've seen various examples with keypress and keydown, but not dedicated on getting the input value.
Is it possible?
$(document).ready(function(){
$("#my_field").keydown (function (e) {
alert (e);
});
});
The returned object has a series of properties but I haven't seen something for value input field attribute.
Is there some way to get it?
I'm trying to get a input text value
Use the val()
:
$("#my_field").keydown (function (e) {
alert ($(this).val());
});
Assuming that #my_field
is the id of input field you want to get the value of.
I'm unclear which you're after here, in case you're after the letter pressed, not the whole value, you can use String.fromCharCode()
, for example:
$(document).ready(function(){
$("#my_field").keydown (function (e) {
alert (String.fromCharCode(e.which));
});
});
You can give it a try here
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