Urb wrote:

I wrote:
> > This is probably a very stupid javascript question, but I am
> baffled by it.
>
>      What's the old saw? There are no stupid question!
> >
> > 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.
> >
>      Not true. JS converts any form field containing numbers to their
> string equivalents. If you want numbers you must use the eval() funtion.
>
> > function calctotal(){
> >     myform.total.value = myform.text1.value + myform.text2.value
> > }
>
>      JS assumes the "+" operator is string concatenation. Try:
>
> >myform.total.value = eval(myform.text1.value) + eval(myform.text2.value)


OK, I think I have found a solution. I've snipped the relevant part of my
page in progress out and put it up at:

http://www.infusiondesign.com/examples/javascript_test.html

I'm wondering if a few folks could give it a visit and try to get it to
crash. I've crash tested it in MSIE 4.x, NS 3 and NS 4 on NT. Am curious
what happens with it on other platforms.

I found, when putting together this little snippet of code that there are
some obvious discrepancies between what will cause an error on one browser,
but not another. To my surprise, I found MSIE 4 to require less specific
code to get the job done...I had to add document. in front of form elements
for NS.

Another surprise I discovered was that when using the internal MSIE browser
in Homesite for testing, if I created a floating point error in the
javascript it would take down Homesite in a single swipe. A little error
message, then poof, Homesite would disappear. Not many things crash my copy
of that program. How could a little thing like javascript do it? Tee hee.

Thanks to everyone who pitched in on this problem, you sent me in the right
direction.

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