View Single Post
Old 11-06-2011, 02:54 PM   PM User | #1
fishbaitfood
New Coder

 
Join Date: Nov 2011
Posts: 30
Thanks: 5
Thanked 0 Times in 0 Posts
fishbaitfood is an unknown quantity at this point
[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) {
	if (e.keyCode >= 48 && e.keyCode <= 57) {
		var amount = String.fromCharCode(e.keyCode);
		$(this).val(amount);
		var price = $(this).parent().next().find("input.input-price").val();
		var total = amount * price;
		$(this).parent().next().next().find("input").val(total);
	}
});
Thank you.
fishbaitfood is offline   Reply With Quote