mexavin
11-07-2003, 06:28 AM
I currently have it set up to count the number of numbers in the 4 text boxex, then add them up. Now, instead, I need to be able to count ranges of numbers, and add them up. EXAMPLE: The user can input 100-105, 107, 109, 111-115.
The box should calculate this as = 13. Not sure how to do this. Any help will be greatly appreciated. Here is what I have so far:
===============
<html>
<head>
<script language="javascript">
function cnt1(w,x){
var y=w.value;
var r = 0;
a=y.replace('\n',' ');
a=a.split(' ');
for (z=0; z<a.length; z++) {if (a[z].length > 0) r++;}
x.value=r;
}
</script>
<script>
function calculate()
{
document.calcform.quantity.value = (eval(document.calcform.qty1.value) + eval(document.calcform.qty2.value) + eval(document.calcform.qty3.value) + eval(document.calcform.qty4.value))
}
</script>
</head>
<body bgcolor="#ffffff" >
<form method=post action="../shopaddtocart.asp" name="calcform">
STEP 1: Enter the first set of numbers <br>
Separate each number with a space<br>
(Example: 101 102 103 104)
<input size="100" class=txtfield name="Feature3" onkeyup="cnt1(this,document.calcform.qty1)">
<br>
<br>
STEP 2: Enter Second set of numbers<br>
Separate each number with a space<br>
(Example: 101 102 103 104)
<input size="100" class=txtfield name="Feature4" onkeyup="cnt1(this,document.calcform.qty2)">
<br>
<br>
STEP 3: Enter Third Set of numbers<br>
Separate each number with a space<br>
(Example: 101 102 103 104)
<input size="100" class=txtfield name="Feature5" onkeyup="cnt1(this,document.calcform.qty3)">
<br>
<br>
STEP 4th: Enter the Fourth set of Numbers<br>
Separate each number with a space<br>
(Example: 101 102 103 104)
<input size="100" class=txtfield name="Feature6" onkeyup="cnt1(this,document.calcform.qty4)">
<br>
<br>
STEP 2: Place Order Total First Set:
<input type="text" name="qty1" value="0" size="5" />
<br />
Total Second Set:
<input type="text" name="qty2" value="0" size="5"/>
<br />
Total Third Set:
<input type="text" name="qty3" value="0" size="5"/>
<br />
Total 4th Set:
<input type="text" name="qty4" value="0" size="5"/>
<br>
<input type="button" value="TOTALS" onClick="calculate()">
<input TYPE=TEXT class=txtfield size=2 maxlength=3 name="quantity" value="0" >
<input type=submit class=submitbtn value="Order" name=Order>
<br></p>
</form>
</body>
</html>
==============
Thanks a bunch,
Mex
The box should calculate this as = 13. Not sure how to do this. Any help will be greatly appreciated. Here is what I have so far:
===============
<html>
<head>
<script language="javascript">
function cnt1(w,x){
var y=w.value;
var r = 0;
a=y.replace('\n',' ');
a=a.split(' ');
for (z=0; z<a.length; z++) {if (a[z].length > 0) r++;}
x.value=r;
}
</script>
<script>
function calculate()
{
document.calcform.quantity.value = (eval(document.calcform.qty1.value) + eval(document.calcform.qty2.value) + eval(document.calcform.qty3.value) + eval(document.calcform.qty4.value))
}
</script>
</head>
<body bgcolor="#ffffff" >
<form method=post action="../shopaddtocart.asp" name="calcform">
STEP 1: Enter the first set of numbers <br>
Separate each number with a space<br>
(Example: 101 102 103 104)
<input size="100" class=txtfield name="Feature3" onkeyup="cnt1(this,document.calcform.qty1)">
<br>
<br>
STEP 2: Enter Second set of numbers<br>
Separate each number with a space<br>
(Example: 101 102 103 104)
<input size="100" class=txtfield name="Feature4" onkeyup="cnt1(this,document.calcform.qty2)">
<br>
<br>
STEP 3: Enter Third Set of numbers<br>
Separate each number with a space<br>
(Example: 101 102 103 104)
<input size="100" class=txtfield name="Feature5" onkeyup="cnt1(this,document.calcform.qty3)">
<br>
<br>
STEP 4th: Enter the Fourth set of Numbers<br>
Separate each number with a space<br>
(Example: 101 102 103 104)
<input size="100" class=txtfield name="Feature6" onkeyup="cnt1(this,document.calcform.qty4)">
<br>
<br>
STEP 2: Place Order Total First Set:
<input type="text" name="qty1" value="0" size="5" />
<br />
Total Second Set:
<input type="text" name="qty2" value="0" size="5"/>
<br />
Total Third Set:
<input type="text" name="qty3" value="0" size="5"/>
<br />
Total 4th Set:
<input type="text" name="qty4" value="0" size="5"/>
<br>
<input type="button" value="TOTALS" onClick="calculate()">
<input TYPE=TEXT class=txtfield size=2 maxlength=3 name="quantity" value="0" >
<input type=submit class=submitbtn value="Order" name=Order>
<br></p>
</form>
</body>
</html>
==============
Thanks a bunch,
Mex