Hi. I have this form and it seems to work just fine, until it needs to recalculate. I would like it to recalculate all fields everytime the Name of the River changes, Number of Rafters changes, or Type of Trip changes.
Would someone here please check it out, play with the form, and let me know where I went wrong?
Thanks!
Here's the page:
Here's the coding:
-------------------------
<SCRIPT LANGUAGE="JavaScript">
<!-- hide contents from old browsers
var Cost, GST, PST, Grand_Total;
function tally()
{
Cost = 0;
var river = ""
var triptype = ""
var tripshort = ""
var rafters = ""
// load number of rafters into 'rafters' field.
if (document.orderform.r_rafters.value > 0) { rafters = document.orderform.r_rafters.value; }
var river = document.orderform.r_river.value
// get the river - if it's tennessee, then cost is $35.99 * number of rafters
if (river = "Tennessee") { Cost = 35.99 * rafters ;
document.orderform.person.value = "$35.99"; }
else if (river = "Nantahala") {
var triptype = document.orderform.r_trip_type.value
var tripshort = triptype.substring(0,2)
if (tripshort = "NG") { // Non guided pricing
if (rafters < 11) { Cost = 12.99 * rafters;
document.orderform.person.value = "$12.99"; }
else if (rafters < 30) { Cost = 11.99 * rafters;
document.orderform.person.value = "$11.99"; }
else if (rafters < 45) { Cost = 10.99 * rafters;
document.orderform.person.value = "$10.99"; }
else if (rafters < 60) { Cost = 9.99 * rafters;
document.orderform.person.value = "$9.99"; }
}
else if (tripshort = "GA") { // Guide assisted pricing
if (rafters < 11) { Cost = 19.99 * rafters;
document.orderform.person.value = "$19.99"; }
else if (rafters < 30) { Cost = 18.99 * rafters;
document.orderform.person.value = "$18.99"; }
else if (rafters < 45) { Cost = 17.99 * rafters;
document.orderform.person.value = "$17.99"; }
else if (rafters < 60) { Cost = 16.99 * rafters;
document.orderform.person.value = "$16.99"; }
}
else if (tripshort = "GB") { // Guide in boat pricing
Cost = 22.99 * rafters;
document.orderform.person.value = "$22.99"; }
}
GST = (Cost * 0.085);
GST = dollar(GST);
Cost = dollar(Cost);
Grand_Total = parseFloat(Cost) + parseFloat(GST);
document.orderform.GST.value = "$" + GST;
Grand_Total = dollar(Grand_Total);
document.orderform.Total.value = "$" + Cost;
document.orderform.GrandTotal.value = "$" + Grand_Total;
}
function dollar (amount)
{
amount = parseInt(amount * 100);
amount = parseFloat(amount/100);
if (((amount) == Math.floor(amount)) && ((amount - Math.floor (amount)) == 0))
{
amount = amount + ".00"
return amount;
}
if ( ((amount * 10) - Math.floor(amount * 10)) == 0)
{
amount = amount + "0";
return amount;
}
if ( ((amount * 100) - Math.floor(amount * 100)) == 0)
{
amount = amount;
return amount;
}
return amount;
}
//-->
</SCRIPT>
---------------------------------
<FORM ACTION="/cgi-bin/asomail.cgi" METHOD="POST" NAME="orderform">
<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2">
<TR>
<TD VALIGN="TOP">
<TABLE WIDTH="350">
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>*Name of River:</B></FONT></TD>
<TD>
<SELECT NAME="r_river" SIZE="1" ONCHANGE="tally()">
<OPTION VALUE="" SELECTED="SELECTED">Choose Trip
River:</OPTION>
<OPTION VALUE="Nantahala">Nantahala</OPTION>
<OPTION VALUE="Tennessee">Tennessee</OPTION>
</SELECT></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>*Number of rafters:</B></FONT></TD>
<TD><INPUT TYPE="TEXT" NAME="r_rafters" SIZE="15" ONBLUR="tally()"></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>*Type of Trip:</B></FONT></TD>
<TD>
<SELECT NAME="r_trip_type" SIZE="1" ONCHANGE="tally()">
<OPTION VALUE="" SELECTED="SELECTED">Choose Type of
Trip:</OPTION>
<OPTION VALUE="GB (Guide-in-boat)">GB
(Guide-in-boat)</OPTION>
<OPTION VALUE="GA (Guide assisted)">GA (Guide
assisted)</OPTION>
<OPTION VALUE="NG (Non-guided)">NG (Non-guided)</OPTION>
</SELECT></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>Total Per Person:</B></FONT></TD>
<TD><INPUT TYPE="TEXT" NAME="person" VALUE="$"></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>Total:</B></FONT></TD>
<TD><INPUT TYPE="TEXT" NAME="Total" VALUE="$"></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>Tax:</B></FONT></TD>
<TD><INPUT TYPE="TEXT" NAME="GST" VALUE="$"></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>Grand Total:</B></FONT></TD>
<TD><INPUT TYPE="TEXT" NAME="GrandTotal" VALUE="$"></TD>
</TR>
</TABLE> </TD>
</TR>
</TABLE> </FORM>
~ lahddah
Would someone here please check it out, play with the form, and let me know where I went wrong?
Thanks!
Here's the page:
Here's the coding:
-------------------------
<SCRIPT LANGUAGE="JavaScript">
<!-- hide contents from old browsers
var Cost, GST, PST, Grand_Total;
function tally()
{
Cost = 0;
var river = ""
var triptype = ""
var tripshort = ""
var rafters = ""
// load number of rafters into 'rafters' field.
if (document.orderform.r_rafters.value > 0) { rafters = document.orderform.r_rafters.value; }
var river = document.orderform.r_river.value
// get the river - if it's tennessee, then cost is $35.99 * number of rafters
if (river = "Tennessee") { Cost = 35.99 * rafters ;
document.orderform.person.value = "$35.99"; }
else if (river = "Nantahala") {
var triptype = document.orderform.r_trip_type.value
var tripshort = triptype.substring(0,2)
if (tripshort = "NG") { // Non guided pricing
if (rafters < 11) { Cost = 12.99 * rafters;
document.orderform.person.value = "$12.99"; }
else if (rafters < 30) { Cost = 11.99 * rafters;
document.orderform.person.value = "$11.99"; }
else if (rafters < 45) { Cost = 10.99 * rafters;
document.orderform.person.value = "$10.99"; }
else if (rafters < 60) { Cost = 9.99 * rafters;
document.orderform.person.value = "$9.99"; }
}
else if (tripshort = "GA") { // Guide assisted pricing
if (rafters < 11) { Cost = 19.99 * rafters;
document.orderform.person.value = "$19.99"; }
else if (rafters < 30) { Cost = 18.99 * rafters;
document.orderform.person.value = "$18.99"; }
else if (rafters < 45) { Cost = 17.99 * rafters;
document.orderform.person.value = "$17.99"; }
else if (rafters < 60) { Cost = 16.99 * rafters;
document.orderform.person.value = "$16.99"; }
}
else if (tripshort = "GB") { // Guide in boat pricing
Cost = 22.99 * rafters;
document.orderform.person.value = "$22.99"; }
}
GST = (Cost * 0.085);
GST = dollar(GST);
Cost = dollar(Cost);
Grand_Total = parseFloat(Cost) + parseFloat(GST);
document.orderform.GST.value = "$" + GST;
Grand_Total = dollar(Grand_Total);
document.orderform.Total.value = "$" + Cost;
document.orderform.GrandTotal.value = "$" + Grand_Total;
}
function dollar (amount)
{
amount = parseInt(amount * 100);
amount = parseFloat(amount/100);
if (((amount) == Math.floor(amount)) && ((amount - Math.floor (amount)) == 0))
{
amount = amount + ".00"
return amount;
}
if ( ((amount * 10) - Math.floor(amount * 10)) == 0)
{
amount = amount + "0";
return amount;
}
if ( ((amount * 100) - Math.floor(amount * 100)) == 0)
{
amount = amount;
return amount;
}
return amount;
}
//-->
</SCRIPT>
---------------------------------
<FORM ACTION="/cgi-bin/asomail.cgi" METHOD="POST" NAME="orderform">
<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2">
<TR>
<TD VALIGN="TOP">
<TABLE WIDTH="350">
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>*Name of River:</B></FONT></TD>
<TD>
<SELECT NAME="r_river" SIZE="1" ONCHANGE="tally()">
<OPTION VALUE="" SELECTED="SELECTED">Choose Trip
River:</OPTION>
<OPTION VALUE="Nantahala">Nantahala</OPTION>
<OPTION VALUE="Tennessee">Tennessee</OPTION>
</SELECT></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>*Number of rafters:</B></FONT></TD>
<TD><INPUT TYPE="TEXT" NAME="r_rafters" SIZE="15" ONBLUR="tally()"></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>*Type of Trip:</B></FONT></TD>
<TD>
<SELECT NAME="r_trip_type" SIZE="1" ONCHANGE="tally()">
<OPTION VALUE="" SELECTED="SELECTED">Choose Type of
Trip:</OPTION>
<OPTION VALUE="GB (Guide-in-boat)">GB
(Guide-in-boat)</OPTION>
<OPTION VALUE="GA (Guide assisted)">GA (Guide
assisted)</OPTION>
<OPTION VALUE="NG (Non-guided)">NG (Non-guided)</OPTION>
</SELECT></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>Total Per Person:</B></FONT></TD>
<TD><INPUT TYPE="TEXT" NAME="person" VALUE="$"></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>Total:</B></FONT></TD>
<TD><INPUT TYPE="TEXT" NAME="Total" VALUE="$"></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>Tax:</B></FONT></TD>
<TD><INPUT TYPE="TEXT" NAME="GST" VALUE="$"></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP"><FONT FACE="Arial" SIZE="2"><B>Grand Total:</B></FONT></TD>
<TD><INPUT TYPE="TEXT" NAME="GrandTotal" VALUE="$"></TD>
</TR>
</TABLE> </TD>
</TR>
</TABLE> </FORM>
~ lahddah