![]() |
[jQuery] Entered digits in input field to be processed as one number
Hello everyone,
I'm figuring out how to process entered digits as one number. For now, I'm only able to process the input with the last entered, single digit. Is there a way to store the entered digits to a string, and then make that string a number again? Or maybe something more sufficient? Code:
$("input.input-amount").live("keypress", function (e) { |
Run the event on the change event rather than the keypress:
Code:
$("input").live("change", function () { |
Hey SB65,
This works, thank you, but my intention was to get the value as soon as you enter a number, for instant calculations. That's why I thought maybe, with the use of my first example, to convert the entered digits to a string, and then back to a number? Now it kinda behaves like .blur(). |
OK.
Maybe I'm missing something but why do you need to go via a string? Won't: Code:
$("input").live("keyup", function (e) {From a brief test in FF7 (only) I got better results with keyup compared to keypress, incidentally. |
Yes, 1, 12, 123, is what I had already.
But when getting that value, I only get the last entered digit, instead of the whole value. So, as I'm entering digits, it needs to continuously adjust the value, so it'll get the whole number, instead of only the last digit. I hope this makes some sense to you. |
Well, the code in my last post will produce 1, 12, 123, not just the last digit.
Your original code produces the value of the keypress - so you get 1, 2, 3, but what you want, I think, is the whole value of the input field - which is what this gives you. |
Hmm, if I use your code, it won't do anything, not even to the console.
EDIT: nevermind, it works now! :D Thanks again SB65!! |
What browser are you using - I only tested in FF7.
EDIT:Works in IE8 as well. |
It's for personal use only, and it works in the browsers I need, so I'm set! ;)
Thanks a bunch, SB65, I think I'm gonna use .live a hell of a lot more from now on. :) |
| All times are GMT +1. The time now is 05:08 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.