/    Sign up×
Community /Pin to ProfileBookmark

How to add to form script

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]*
fv);
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:[email protected]“>
<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>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@nszczepanskiJul 26.2005 — I will help you since no one else here would. I have a thread that went unanswered too. I think if they are considered easy people just ignore them.

Anyway, you want to copy the code below and apply it to ever product instance cna change in these four areas:

[COLOR=Navy]1. Name "f_qty4"

2. Select Name "product4"

3. Name "f_price4"

4. Name "f_tot4"[/COLOR]


See my code I added product4.

[CODE]<td valign=top align=right><input type=text name="f_qty4" 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="product4" 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>[/CODE]


-Neil
Copy linkTweet thisAlerts:
@cheapgaryauthorJul 27.2005 — Neil,

What's this ? A Forum with HEART ! I don't believe it. Thank God. Neil, where have you been? If you want to talk forums with attitude I can show you some! This ain't so bad. At least nobody called me a name.

Anyway, cool. Thanks so much. I'll sit with this later and work it out. I have some other questions about this form but one thing at a time. Thanks.

Gary
Copy linkTweet thisAlerts:
@cheapgaryauthorJul 27.2005 — oops..
×

Success!

Help @cheapgary spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...