Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] 1+1+1=111?


  • From: javascript@xxxxxxxxxx (Peter Brunone)
  • Subject: [Javascript] 1+1+1=111?
  • Date: Wed, 27 Jun 2001 13:13:22 -0500

This is a multi-part message in MIME format.

------=_NextPart_000_0050_01C0FF0A.F150BCD0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thomas,

    The answer to your problems is the parseInt() function, e.g.

var total =3D parseInt(formname.field1name.value) + =
parseInt(formname.field2name.value);

    Form data is treated as strings unless you specify otherwise.

Cheers,

Peter
  ----- Original Message -----=20
  From: McCoy, Thomas=20
  To: 'javascript@xxxxxxxxxx'=20
  Sent: Wednesday, June 27, 2001 1:04 PM
  Subject: [Javascript] 1+1+1=3D111?


  Hello all!


  I am trying to create a form that uses client-side Javascript to sum =
numerical data.

  The form has six blanks where numbers are entered.  The seventh box =
will display the mathematical total of the numbers entered in the six =
boxes.  So far, I can only get the 7th box to either add the html tags =
together (not what I want) or compile the numbers in the box (if the =
first six contain 1,2,3,4,5,6... I get 123456 in the Total box).  Any =
ideas, before I pull all my hair out?


  Sincerely,
  Thomas McCoy

------=_NextPart_000_0050_01C0FF0A.F150BCD0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Thomas,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; The answer to your =
problems is=20
the parseInt() function, e.g.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>var total =3D =
parseInt(formname.field1name.value) +=20
parseInt(formname.field2name.value);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Form data is treated =
as strings=20
unless you specify otherwise.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cheers,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Peter</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3DTMccoy@xxxxxxxxxxxxxxxxxxxxxxxx=20
  href=3D"mailto:TMccoy@xxxxxxxxxxxxxxxxxxxxxxxx";>McCoy, Thomas</A> =
</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Djavascript@xxxxxxxxxx=20
  href=3D"mailto:'javascript@xxxxxxxxxx'">'javascript@xxxxxxxxxx'</A> =
</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, June 27, 2001 =
1:04=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Javascript] =
1+1+1=3D111?</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN =
class=3D867005917-27062001>Hello=20
  all!</SPAN></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN=20
  class=3D867005917-27062001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN=20
  class=3D867005917-27062001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN class=3D867005917-27062001>I am =
trying to=20
  create a form that uses client-side&nbsp;Javascript to sum numerical=20
  data.</SPAN></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN=20
  class=3D867005917-27062001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN class=3D867005917-27062001>The =
form has six=20
  blanks where numbers are entered.&nbsp; The seventh =
box&nbsp;will&nbsp;display=20
  the mathematical total&nbsp;of the numbers entered in the&nbsp;six=20
  boxes.&nbsp; So far, I can only get the 7th box to either add the html =
tags=20
  together (not what I want) or compile the numbers&nbsp;in the box (if =
the=20
  first six contain 1,2,3,4,5,6... I get 123456 in the Total box).&nbsp; =
Any=20
  ideas, before I pull all my hair out?</SPAN></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN=20
  class=3D867005917-27062001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2><SPAN=20
  class=3D867005917-27062001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Sincerely,</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>Thomas=20
McCoy</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0050_01C0FF0A.F150BCD0--