Hi,
I’m trying to learn how to add additional products list menus to this form while keeping the auto-calculating feature of it working. I break it everytime.
Any help to tell me how to do it would be greatly appreciated.
Regards,
Gary
<html>
<head>
<title>Online Order Form</title>
<SCRIPT LANGUAGE=”JavaScript”>
<!– hide
function MakeArray(n)
{
this.length = n;
for(var i = 1; i <= n; i++)
{
this[i] = 0
}
return this
}
function f_tax(num)
{
if(num)
{
if(document.input.TAX.checked)
{
// this line modifies the local tax amount
document.input.f_res.value=Math.round(8.25*num)/100;
}
else
{
document.input.f_res.value=0;
}
}
cal_gtot();
}
function cal_gtot()
{
var tamp=0;
if(document.input.f_stot.value.length != 0)
{
tamp+=parseFloat(document.input.f_stot.value);
}
if(document.input.f_res.value.length != 0)
{
tamp+=parseFloat(document.input.f_res.value);
}
document.input.f_gtot.value=tamp;
}
function process(sel)
{
var t_price = new MakeArray(process.arguments.length);
var line=sel.name.charAt(sel.name.length-1);
for(var i=1;i<process.arguments.length;i++)
{
t_price[i-1]=parseFloat(process.arguments[i]);
}
if(document.input[“f_qty”+line].value.length != 0)
{
var fv=parseFloat(document.input[“f_qty”+line].value);
if(navigator.appVersion.charAt(navigator.appVersion.indexOf(“(“)+1) == “W” || navigator.appVersion.charAt(navigator.appVersion.indexOf(“(“)+1) == “M”)
{
if(fv == 0)
{
line++;
alert(“the qty at line “+line+” must be a number”);
return;
}
}
else
{
if(isNaN(fv))
{
line++;
alert(“the qty at line “+line+” must be a number”);
return;
}
}
if(sel.name.substring(0,sel.name.length-1)==”product”)
{
document.input[“f_tot”+line].value=eval(t_price[sel.selectedIndex]*fv);
document.input[“f_price”+line].value=t_price[sel.selectedIndex];
}
else
{
document.input[“f_tot”+line].value=eval(t_price[document.input[“product”+line].selectedIndex]
document.input[“f_price”+line].value=t_price[document.input[“product”+line].selectedIndex];
}
}
var i=0;
var total=0;
while(document.input[“f_tot”+i])
{
if(document.input[“f_tot”+i].value.length != 0)
{
total+=parseFloat(document.input[“f_tot”+i].value);
}
i++;
}
document.input.f_stot.value=total;
f_tax(total);
cal_gtot();
}
function f_send()
{
if( document.input.f_name.value.length == 0
||document.input.f_addr.value.length == 0
||document.input.f_stat.value.length == 0
||document.input.f_country.value.length == 0
||document.input.f_zip.value.length == 0
||document.input.f_phone.value.length == 0)
{
alert(“You must complete the form first!”);
return;
}
if (confirm(“Press ok to send the order”))
{
document.input.submit();
}
}
//–>
</SCRIPT>
</head>
<body bgcolor=”#ffffff”>
<center>
<FONT SIZE=5><B>Online Order Form</B></FONT>
<form name=input METHOD=”post” ACTION=”mailto:
<table>
<TR>
<TH ALIGN=right>Name</TH>
<TD COLSPAN=5><INPUT NAME=”f_name” value=”” SIZE=59></TD>
</TR>
<TR>
<TH ALIGN=right>Address</TH>
<TD COLSPAN=5><INPUT NAME=”f_addr” value=”” SIZE=59></TD>
</TR>
<TR>
<TH ALIGN=right>City</TH>
<TD><INPUT NAME=”f_city” value=”” maxlength = 20 SIZE=20></TD>
<TH ALIGN=right>State/Province</TH>
<TD COLSPAN=3><INPUT NAME=”f_stat” value=”” maxlength = 30 SIZE=20></TD>
</TR>
<TR>
<TH ALIGN=right>Country</TH>
<TD><INPUT NAME=”f_country” value=”” maxlength = 20 SIZE=20></TD>
<TH ALIGN=right>Zip/Postal Code</TH>
<TD COLSPAN=3><INPUT NAME=”f_zip” value=”” maxlength = 10 SIZE=20></TD>
</TR>
<TR>
<TH ALIGN=right>Billing Phone</TH>
<TD><INPUT NAME=”f_phone” value=”” maxlength = 21 SIZE=12></TD>
<TH ALIGN=right>Email Address</TH>
<TD COLSPAN=3><INPUT NAME=”f_email” value=”” maxlength = 100 SIZE=20></td>
</tr>
<tr>
<td colspan=2 align=center>
<INPUT TYPE=”submit” name=”f_submit” value=” SUBMIT ” onClick=’f_send();’>
</td>
<td colspan=4 align=center>
<INPUT TYPE=”RESET” value=”RESET”>
</td>
</tr>
<tr>
<td ROWSPAN=8><pre> </pre></td>
<th align=right>Qty .</th>
<th align=center>Product</th>
<th align=center>Price</th>
<th align=center>Total</th>
<th ROWSPAN=8><pre> </pre></td>
</tr>
<tr>
<td valign=top align=right><input type=text name=”f_qty0″ size=3 onChange=’process(this, “1.55”, “2.25”, “3.52”, “4.79”, “5.99”, “6.99”, “7.56”, “8.25”, “9.99”, “10.99”);’>
</td>
<td valign=top>
<SELECT name=”product0″ onChange=’process(this, “1.55”, “2.25”, “3.52”, “4.79”, “5.99”, “6.99”, “7.56”, “8.25”, “9.99”, “10.99”);’>
<option>gary 1 </option>
<option>gary 2 </option>
<option>product 3 </option>
<option>product 4 </option>
<option>product 5 </option>
<option>product 6 </option>
<option>product 7 </option>
<option>product 8 </option>
<option>product 9 </option>
<option>product 10 </option>
<option selected>select a product </option>
</select>
</td>
<td valign=top><input type=text name=”f_price0″ size=8 onFocus=”this.blur();”></td>
<td valign=top><input type=text name=”f_tot0″ size=8 onFocus=”this.blur();”></td>
</tr>
<tr>
<td valign=top align=right><input type=text name=”f_qty1″ size=3 onChange=’process(this, “1.55”, “2.25”, “3.52”, “4.79”, “5.99”, “6.99”, “7.56”, “8.25”, “9.99”, “10.99”);’>
</td>
<td valign=top>
<SELECT name=”product1″ onChange=’process(this, “1.55”, “2.25”, “3.52”, “4.79”, “5.99”, “6.99”, “7.56”, “8.25”, “9.99”, “10.99”);’>
<option>product 1 <option>product 2 <option>product 3
<option>product 4 <option>product 5 <option>product 6 <option>product 7
<option>product 8 <option>product 9 <option>product 10
<option selected>select a product
</select>
</td>
<td valign=top><input type=text name=”f_price1″ size=8 onFocus=”this.blur();”></td>
<td valign=top><input type=text name=”f_tot1″ size=8 onFocus=”this.blur();”></td>
</tr>
<tr>
<td valign=top align=right><input type=text name=”f_qty2″ size=3 onChange=’process(this, “1.55”, “2.25”, “3.52”, “4.79”, “5.99”, “6.99”, “7.56”, “8.25”, “9.99”, “10.99”);’>
<td valign=top>
<SELECT name=”product2″ onChange=’process(this, “1.55”, “2.25”, “3.52”, “4.79”, “5.99”, “6.99”, “7.56”, “8.25”, “9.99”, “10.99”);’>
<option>product 1 <option>product 2 <option>product 3
<option>product 4 <option>product 5 <option>product 6 <option>product 7
<option>product 8 <option>product 9 <option>product 10
<option selected>select a product
</select>
</td>
<td valign=top><input type=text name=f_price2 size=8 onFocus=”this.blur();”></td>
<td valign=top><input type=text name=f_tot2 size=8 onFocus=”this.blur();”></td>
</tr>
<tr>
<td></td>
<td></td>
<th>Subtotal</th>
<td><input type=text name=f_stot size=8 onFocus=”this.blur();”></td>
</tr>
<tr>
<th colspan=2 align=right>CA Residents <input type=checkbox name=TAX onClick=”f_tax(document.input.f_stot.value);”></th>
<th>Taxes</th>
<td><input type=text name=f_res size=8 onFocus=”this.blur();”></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<th>Total</th>
<td><input type=text name=f_gtot size=8 onFocus=”this.blur();”></td>
</tr>
</table>
</form>
</center>
</body>
</html>