This is probably a very stupid javascript question, but I am baffled by it.

I'm trying to make a simple "calculator" type form where the values in a
number of text boxes are added together to get the total. I have named my
text boxes and put an onClick funtion in an <input type=button> tag. In
theory, when you click the button, the numbers in the text boxes will be
added together and the result will show in a "total" text box.

Seems simple enough. Problem is that my javascript is treating the numbers
in the text boxes as strings, so instead of getting 1 + 2 + 3 = 6 I get 1 +
2 + 3 = 123.

I'm doing this in the script:

function calctotal(){
        myform.total.value = myform.text1.value + myform.text2.value
}

This is being called on the onClick. The myform.total.value should be the
sum of the numbers, but they are being treated as strings. The onClick is
working, because I'm seeing the results in the text box where I expect them.
I've been digging through various javascript sources looking for an answer,
but can't find one. I've seen eval(a + b) used to combine strings, but is
there some opposite function to force math?

Thanks,
Jack

____________________________________________________________________
--------------------------------------------------------------------
 Join The Web Consultants Association :  Register on our web site Now
Web Consultants Web Site : http://just4u.com/webconsultants
If you lose the instructions All subscription/unsubscribing can be done
directly from our website for all our lists.
---------------------------------------------------------------------

Reply via email to