...

View Full Version : Handling the textbox entry as a number



CreativeGPX
03-19-2004, 07:05 PM
I'm having a problem with the following. I am trying to add the number entered in the text box to the variable vduron13. Everytime that i add however it returns the textbox entry then its old value. For example, entering 5 into the textbox would return 50 and if repeated 550 and so on. Does anyone know how would I fix this?

vduron13 = 0;
var quantity = 0;
var quantity = document.form.duron13amount.value;
vduron13 = quantity+vduron13;

Choopernickel
03-19-2004, 07:10 PM
vduron13 = 0;
var quantity =new Number(document.form.duron13amount.value);
vduron13 = quantity+vduron13;

Using the Number() constructor will give you a math-able (?) number based on the string input. Ha HA! More versatile than parseFloat() and parseInt().

Unless I'm wrong again.

Also: You can't legally initialize the same variable with the "var" keyword more than once.

CreativeGPX
03-19-2004, 07:29 PM
Thanks it works perfect. And about the only using var once, I did that in my code, but i guess that i messed it up typing it on here.

Kor
03-20-2004, 08:38 AM
In fact Number() it is used for other purposes than parseInt(). Eachone has its merrits :D

parseInt('123') and Number('123') will do the same, but

only parseInt('123 px') will return 123

only Number(true) will convert the boolean to 1



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum