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 14:35:56 -0500
This is a multi-part message in MIME format.
------=_NextPart_000_015C_01C0FF16.79FB7560
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Here's a revised version of your sumboxes function that does the =
trick. I not only had to parseInt the values, but then I checked to see =
if there *was* a value (if length > 0) and changed the variable to a =
zero if there was nothing in the box.
FYI, I used a one-line conditional that states the following: set =
this variable (prepHours). If (?) the length of the form field value is =
greater than zero, then set it equal to =
parseInt(f.Prep_Hours___________________.value) , and otherwise (:) set =
it equal to zero.
function sumboxes() {=20
var f=3Ddocument.myform;=20
var prepHours =3D =
f.Prep_Hours___________________.value.length>0?parseInt(f.Prep_Hours_____=
______________.value):0;
var officeHours =3D =
f.Office_Hours_________________.value.length>0?parseInt(f.Office_Hours___=
______________.value):0;
var inServiceHours =3D =
f.In_Service_Hours_____________.value.length>0?parseInt(f.In_Service_Hour=
s_____________.value):0;
var lessonHours =3D =
f.Lesson_Hours_________________.value.length>0?parseInt(f.Lesson_Hours___=
______________.value):0;
var travelHours =3D =
f.Travel_Hours_________________.value.length>0?parseInt(f.Travel_Hours___=
______________.value):0;
var otherHours =3D =
f.Other_Hours__________________.value>0?parseInt(f.Other_Hours___________=
_______.value):0;
var totalHours =3D prepHours + officeHours + inServiceHours + =
lessonHours + travelHours + otherHours;
f.Total_Hours__________________.value =3D totalHours;
}
Cheers,
Peter
----- Original Message -----=20
From: McCoy, Thomas=20
To: 'peter@xxxxxxxxxxx'=20
Sent: Wednesday, June 27, 2001 2:02 PM
Subject: RE: [JavaScript] 1+1+1=3D111?
No luck, just popup error dialog boxes. I am not yet proficient in =
JavaScript, and I think that may be a big source of my troubles.
Here is a link to the form with the problem I described =
http://www.city.newport-beach.ca.us/nbpl/literacyform02.htm (enter in =
some numbers in the hours fields, and watch the "Total Hours" box)
I appreciate any help you may provide!
-----Original Message-----
From: Peter Brunone [mailto:peter@xxxxxxxxxxx]
Sent: Wednesday, June 27, 2001 11:13 AM
To: javascript@xxxxxxxxxx
Subject: Re: [Javascript] 1+1+1=3D111?
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_015C_01C0FF16.79FB7560
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></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> Here's a revised =
version of your=20
sumboxes function that does the trick. I not only had to parseInt =
the=20
values, but then I checked to see if there *was* a value (if length > =
0) and=20
changed the variable to a zero if there was nothing in the =
box.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> FYI, I used a =
one-line=20
conditional that states the following: set this variable=20
(prepHours). If (?) the length of the form field value is greater =
than=20
zero, then set it equal to =
parseInt(f.Prep_Hours___________________.value) , and=20
otherwise (:) set it equal to zero.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>function sumboxes() { =
<BR> var=20
f=3Ddocument.myform; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> var prepHours =3D=20
f.Prep_Hours___________________.value.length>0?parseInt(f.Prep_Hours__=
_________________.value):0;<BR> var=20
officeHours =3D=20
f.Office_Hours_________________.value.length>0?parseInt(f.Office_Hours=
_________________.value):0;<BR> var=20
inServiceHours =3D=20
f.In_Service_Hours_____________.value.length>0?parseInt(f.In_Service_H=
ours_____________.value):0;<BR> var=20
lessonHours =3D=20
f.Lesson_Hours_________________.value.length>0?parseInt(f.Lesson_Hours=
_________________.value):0;<BR> var=20
travelHours =3D=20
f.Travel_Hours_________________.value.length>0?parseInt(f.Travel_Hours=
_________________.value):0;<BR> var=20
otherHours =3D=20
f.Other_Hours__________________.value>0?parseInt(f.Other_Hours________=
__________.value):0;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> var totalHours =3D prepHours + =
officeHours +=20
inServiceHours + lessonHours + travelHours + otherHours;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> f.Total_Hours__________________.value =3D=20
totalHours;<BR> }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Cheers,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </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=3Dpeter@xxxxxxxxxxx=20
href=3D"mailto:'peter@xxxxxxxxxxx'">'peter@xxxxxxxxxxx'</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, June 27, 2001 =
2:02=20
PM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> RE: [JavaScript]=20
1+1+1=3D111?</DIV>
<DIV><BR></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN =
class=3D078105618-27062001>No=20
luck, just popup error dialog boxes. I am not yet proficient in=20
JavaScript, and I think that may be a big source of my=20
troubles.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
class=3D078105618-27062001></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D078105618-27062001><FONT=20
color=3D#0000ff>Here is a link to the form with the problem I =
described=20
</FONT><A=20
=
href=3D"http://www.city.newport-beach.ca.us/nbpl/literacyform02.htm"><FON=
T=20
=
color=3D#0000ff>http://www.city.newport-beach.ca.us/nbpl/literacyform02.h=
tm</FONT></A><FONT=20
color=3D#0000ff> (enter in some numbers in the =
hours fields, and=20
watch the "Total Hours" box)</FONT></SPAN></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
class=3D078105618-27062001></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN =
class=3D078105618-27062001>I=20
appreciate any help you may provide!</SPAN></FONT></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
<DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT =
face=3DTahoma=20
size=3D2>-----Original Message-----<BR><B>From:</B> Peter Brunone=20
[mailto:peter@xxxxxxxxxxx]<BR><B>Sent:</B> Wednesday, June 27, 2001 =
11:13=20
AM<BR><B>To:</B> javascript@xxxxxxxxxx<BR><B>Subject:</B> Re: =
[Javascript]=20
1+1+1=3D111?<BR><BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Thomas,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> The answer to =
your problems=20
is the parseInt() function, e.g.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </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> </DIV>
<DIV><FONT face=3DArial size=3D2> Form data is =
treated as=20
strings unless you specify otherwise.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Cheers,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </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]=20
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> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D867005917-27062001></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D867005917-27062001>I am trying to=20
create a form that uses client-side Javascript to sum =
numerical=20
data.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D867005917-27062001></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D867005917-27062001>The form has=20
six blanks where numbers are entered. The seventh=20
box will display the mathematical total of the =
numbers=20
entered in the six boxes. So far, I can only get the =
7th box to=20
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=20
123456 in the Total box). Any ideas, before I pull all my =
hair=20
out?</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D867005917-27062001></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D867005917-27062001></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Sincerely,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Thomas=20
=
McCoy</FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_015C_01C0FF16.79FB7560--
- Prev by Date: [Javascript] 1+1+1=111?
- Next by Date: [Javascript] Remote Scripting
- Previous by thread: [Javascript] 1+1+1=111?
- Next by thread: [Javascript] I.E.: 1+1=1. Worse yet, Netscape: 1+1 =___
- Index(es):