Stupid Javascript question
Jim Skehill
JimS-pFJmkVL1u50 at public.gmane.org
Mon Feb 14 17:44:49 UTC 2005
>You are right, replacing a ='2' with a=2 will work. However, I have
>rarely written a javascript function where I hard-code two variables and
>add them together. The majority of the time my calculations are based
>on user input in text boxes or select boxes. So try your example but
>get your value from the input box. Any value that comes from input
>boxes on a form are always string values. This is why you have to
>"trick" javascript into thinking your string value is a number or else
>you will just concat your two values.
If what you want to do is convert a string to a number , I prefer the syntax
aNumber = new Number(aString);
It makes it pretty clear what you are doing.
For example in my previous AddTest function if you wanted to take the input
value and add it to itself it would look like this:
function AddTest(input) {
a = new Number(input.value);
input.value = a+a;
}
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list