SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: calculating a total from a form
-
Oct 14, 2003, 08:12 #1
- Join Date
- Aug 2001
- Location
- Amsterdam
- Posts
- 788
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
calculating a total from a form
Hi all ...
Let me first of all warn you I'm not really good a Javascript (jet) [img]images/smilies/xeye.gif[/img]
I want to calculate a total for a form and alert if some conditions aren't met ...
I'm going completely crazy here ... so any help would be appreciated.. here's the deal ..
there is 4 input's with name A - D their values need to be between 0 -50 and the total must be 50 exactly .....
this is what I got so far
PHP Code:function Optellen()
{
var total
total = 0
A = document.CQS.A.value
B = document.CQS.B.value
C = document.CQS.C.value
D = document.CQS.D.value
if(A = '' ) { A = 0 }
if(B = '' ) { B = 0 }
if(C = '' ) { C = 0 }
if(D = '' ) { D = 0 }
total += eval(A)
total += eval(B)
total += eval(C)
total += eval(D)
if (total > 50)
{
alert("The total can not be more than 50" )
}
else
{
document.CQS.total.value = total
}
}
Please help
Edit:
I'm using the PHP code tag so I get nice outlined code but ofcourse it's javascriptthe neigbours (free) WIFI makes it just a little more fun
-
Oct 14, 2003, 08:31 #2
- Join Date
- Dec 2002
- Location
- Alabama, USA
- Posts
- 2,560
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Use parseInt() instead of 'eval()'. And then use isNaN() before validating the values.
Cross-Browser.com, Home of the X Library
-
Oct 14, 2003, 09:07 #3
- Join Date
- Aug 2001
- Location
- Amsterdam
- Posts
- 788
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks I got it working now...
the neigbours (free) WIFI makes it just a little more fun
Bookmarks