Newbie here: I could use some assistance with the following order form. The form currently calculates the total for purchases but I can't seem to get it to calculate a Grand Total including Quantity and Taxes. I'm currently copy the quantity total to a hidden field called "charge_total". I then want to take that amount and include it in the Items list such as "Item1". So it will total both quantity total and grand total together. If someone can point me in the right direction it would be appreciated. Thanks, Here is the script: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script type="text/JavaScript"><!-- /* _____________________________________ /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ | Another JavaScript from Uncle Jim | | Feel free to copy, use and change | | this script as long as this part | | remains unchanged. You can visit | | my website at http://jdstiles.com | | for more scripts like this one. | | Created: 1998 Updated: 2006 | \_____________________________________/ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ */ function CalculateTotal(frm) { var order_total = 0 // Run through all the form fields for (var i=0; i < frm.elements.length; ++i) { // Get the current field form_field = frm.elements // Get the field's name form_name = form_field.name // Is it a "product" field? if (form_name.substring(0,4) == "PROD") { // If so, extract the price from the name item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1)) // Get the quantity item_quantity = parseInt(form_field.value) // Update the order total if (item_quantity >= 0) { order_total += item_quantity * item_price } } } // Display the total rounded to two decimal places frm.Total.value = round_decimals(order_total, 2) } function round_decimals(original_number, decimals) { var result1 = original_number * Math.pow(10, decimals) var result2 = Math.round(result1) var result3 = result2 / Math.pow(10, decimals) return pad_with_zeros(result3, decimals) } function pad_with_zeros(rounded_value, decimal_places) { // Convert the number to a string var value_string = rounded_value.toString() // Locate the decimal point var decimal_location = value_string.indexOf(".") // Is there a decimal point? if (decimal_location == -1) { // If no, then all decimal places will be padded with 0s decimal_part_length = 0 // If decimal_places is greater than zero, tack on a decimal point value_string += decimal_places > 0 ? "." : "" } else { // If yes, then only the extra decimal places will be padded with 0s decimal_part_length = value_string.length - decimal_location - 1 } // Calculate the number of decimal places that need to be padded with 0s var pad_total = decimal_places - decimal_part_length if (pad_total > 0) { // Pad the string with 0s for (var counter = 1; counter <= pad_total; counter++) value_string += "0" } return value_string } function copytext(source_id, dest_id) { var s = document.getElementById(source_id); var d = document.getElementById(dest_id); d.value=s.value; } //--> var Cost, GST, PST, Grand_Total; function tally() { Cost = 0; if (document.orderform.Item1.checked) { Cost = Cost + 15.00; } if (document.orderform.charge_total.change) { Cost = Cost; } GST = (Cost * 0.07); PST = (Cost * 0.07); Cost = dollar(Cost); GST = dollar(GST); PST = dollar(PST); Grand_Total = parseFloat(Cost) + parseFloat(GST) + parseFloat(PST); Grand_Total = dollar(Grand_Total); document.orderform.Total.value = "$" + Cost; document.orderform.GST.value = "$" + GST; document.orderform.PST.value = "$" + PST; 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> <style type="text/css"> <!-- .style1 {font-family: Arial, Helvetica, sans-serif} .style2 {font-weight: bold} --> </style> </head> <body> <form method="post" name="orderform" action="mailto:me@mydomain.com" enctype="text/plain""> <p> </p> <table width="735" height="34" border ="0" cellpadding="3" cellspacing="3" bordercolor="#FFFFFF"> <tr> <td width="88" height="28" align="center" bgcolor="#CCCCCC"><input type="text" name="PROD_SP_24.95" size="4" maxlength="4" onchange="CalculateTotal(this.form)" /></td> <td width="221" bgcolor="#FFFFBB"><div align="left"><span class="style1"> Tool</span></div></td> <td width="396" align="right" bgcolor="#FFCC00"><div align="center"><strong>$24.95</strong></div></td> </tr> </table> <table border="0"><tr><td colspan="4"> <p> <input type="checkbox" name="Item1" value="Item1_chosen" onclick="tally()" /> click here if you live within North America for shipping ($15.00) <p> <input type="hidden" name="charge_total" id="RESULT_TextField-3" onchange="tally()" /> </td></tr> <tr><td width="159"> Total <input name="Input" class="ee147" id="Total" value="$0" onfocus="this.form.elements[0].focus();" size="10"/></td> <td width="288"> PST (7%) <input type="text" name="PST" value="$0" size="6"></td> <td colspan="2"> GST (7%) <input type="text" name="GST" value="$0" size="6"></td></tr> <tr><td> Grand Total <input type="text" name="GrandTotal" value="$0" size="8"></td></tr> <tr><td>Company Name:</td><td colspan="3"><input type="Text" name="Company" size="35" maxlength="40"></td></tr> <tr><td>Contact Name:</td><td colspan="3">First <input type="Text" name="FirstName" size="15" maxlength="20"> Last <input type="Text" name="LastName" size="15" maxlength="20"></td></tr> <tr><td>Address</td><td><input type="Text" name="Street" size="20" maxlength="40"></td></tr> <tr><td>City</td><td><input type="Text" name="City" size="20" maxlength="20"></td><td width="124">Province/State:</td> <td width="120"><input type="Text" name="Province" size="20" maxlength="40"></td></tr> <tr><td>Country:</td><td><input type="Text" name="Country" size="20" maxlength="20"></td><td>Code:</td> <td><input type="Text" name="Code" size="9" maxlength="10"></td></tr> <tr> <td>Phone:</td><td><input type="Text" name="Area" size="3" maxlength="5"> <input type="Text" name="Phone" size="8" maxlength="10"></td><td>Fax:</td> <td><input type="Text" name="AreaFax" size="3" maxlength="5"> <input type="Text" name="Fax" size="8" maxlength="10"></td></tr> <tr><td>Email Address:</td><td colspan=2><input type="Text" name="Email" size="30" maxlength="30"></td></tr> <tr><td colspan="4" height="3"><hr></td></tr> <tr> <td colspan="4" align="center"><div align="left"> <input name="RESET" type="reset" value="CLEAR FORM" /> <br /> <table width="369" border="0"> <tr> <td id="TOTAL" width="198"><input name="submit" type="submit" onclick="copytext('TOTAL', 'RESULT_TextField-3')" value="Click to proceed to Secure Page" /></td> <td width="529"> </td> </tr> </table> </div></td> </tr> </table> </form></CENTER> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script type="text/JavaScript"><!-- /* _____________________________________ /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ | Another JavaScript from Uncle Jim | | Feel free to copy, use and change | | this script as long as this part | | remains unchanged. You can visit | | my website at http://jdstiles.com | | for more scripts like this one. | | Created: 1998 Updated: 2006 | \_____________________________________/ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ */ var GST, PST, Grand_Total; var Total=0; function CalculateTotal(frm) { var order_total = 0 // Run through all the form fields for (var i=0; i < frm.elements.length; ++i) { // Get the current field form_field = frm.elements // Get the field's name form_name = form_field.name // Is it a "product" field? if (form_name.substring(0,4) == "PROD") { // If so, extract the price from the name item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1)) // Get the quantity item_quantity = parseInt(form_field.value) // Update the order total if (item_quantity >= 0) { order_total += item_quantity * item_price } } } // Display the total rounded to two decimal places frm.Total.value = round_decimals(order_total, 2); Total = order_total; } function round_decimals(original_number, decimals) { var result1 = original_number * Math.pow(10, decimals) var result2 = Math.round(result1) var result3 = result2 / Math.pow(10, decimals) return pad_with_zeros(result3, decimals) } function pad_with_zeros(rounded_value, decimal_places) { // Convert the number to a string var value_string = rounded_value.toString() // Locate the decimal point var decimal_location = value_string.indexOf(".") // Is there a decimal point? if (decimal_location == -1) { // If no, then all decimal places will be padded with 0s decimal_part_length = 0 // If decimal_places is greater than zero, tack on a decimal point value_string += decimal_places > 0 ? "." : "" } else { // If yes, then only the extra decimal places will be padded with 0s decimal_part_length = value_string.length - decimal_location - 1 } // Calculate the number of decimal places that need to be padded with 0s var pad_total = decimal_places - decimal_part_length if (pad_total > 0) { // Pad the string with 0s for (var counter = 1; counter <= pad_total; counter++) value_string += "0" } return value_string } function copytext(source_id, dest_id) { var s = document.getElementById(source_id); var d = document.getElementById(dest_id); d.value=s.value; } //--> function tally() { var Cost = Total; if (document.orderform.Item1.checked) { Cost = Cost + 15.00; } if (document.orderform.charge_total.change) { Cost = Cost; } GST = (Cost * 0.07); PST = (Cost * 0.07); Cost = dollar(Cost); GST = dollar(GST); PST = dollar(PST); Grand_Total = parseFloat(Cost) + parseFloat(GST) + parseFloat(PST); Grand_Total = dollar(Grand_Total); document.orderform.Total.value = "$" + Cost; document.orderform.GST.value = "$" + GST; document.orderform.PST.value = "$" + PST; 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> <style type="text/css"> <!-- .style1 {font-family: Arial, Helvetica, sans-serif} .style2 {font-weight: bold} --> </style> </head> <body> <form method="post" name="orderform" action="mailto:me@mydomain.com" enctype="text/plain""> <p> </p> <table width="735" height="34" border ="0" cellpadding="3" cellspacing="3" bordercolor="#FFFFFF"> <tr> <td width="88" height="28" align="center" bgcolor="#CCCCCC"><input type="text" name="PROD_SP_24.95" size="4" maxlength="4" onchange="CalculateTotal(this.form)&tally()" /></td> <td width="221" bgcolor="#FFFFBB"><div align="left"><span class="style1"> Tool</span></div></td> <td width="396" align="right" bgcolor="#FFCC00"><div align="center"><strong>$24.95</strong></div></td> </tr> </table> <table border="0"><tr><td colspan="4"> <p> <input type="checkbox" name="Item1" value="Item1_chosen" onclick="tally()" /> click here if you live within North America for shipping ($15.00) <p> <input type="hidden" name="charge_total" id="RESULT_TextField-3" onchange="tally()" /> </td></tr> <tr><td width="159"> Total <input name="Input" class="ee147" id="Total" value="$0" onfocus="this.form.elements[0].focus();" size="10"/></td> <td width="288"> PST (7%) <input type="text" name="PST" value="$0" size="6"></td> <td colspan="2"> GST (7%) <input type="text" name="GST" value="$0" size="6"></td></tr> <tr><td> Grand Total <input type="text" name="GrandTotal" value="$0" size="8"></td></tr> <tr><td>Company Name:</td><td colspan="3"><input type="Text" name="Company" size="35" maxlength="40"></td></tr> <tr><td>Contact Name:</td><td colspan="3">First <input type="Text" name="FirstName" size="15" maxlength="20"> Last <input type="Text" name="LastName" size="15" maxlength="20"></td></tr> <tr><td>Address</td><td><input type="Text" name="Street" size="20" maxlength="40"></td></tr> <tr><td>City</td><td><input type="Text" name="City" size="20" maxlength="20"></td><td width="124">Province/State:</td> <td width="120"><input type="Text" name="Province" size="20" maxlength="40"></td></tr> <tr><td>Country:</td><td><input type="Text" name="Country" size="20" maxlength="20"></td><td>Code:</td> <td><input type="Text" name="Code" size="9" maxlength="10"></td></tr> <tr> <td>Phone:</td><td><input type="Text" name="Area" size="3" maxlength="5"> <input type="Text" name="Phone" size="8" maxlength="10"></td><td>Fax:</td> <td><input type="Text" name="AreaFax" size="3" maxlength="5"> <input type="Text" name="Fax" size="8" maxlength="10"></td></tr> <tr><td>Email Address:</td><td colspan=2><input type="Text" name="Email" size="30" maxlength="30"></td></tr> <tr><td colspan="4" height="3"><hr></td></tr> <tr> <td colspan="4" align="center"><div align="left"> <input name="RESET" type="reset" value="CLEAR FORM" /> <br /> <table width="369" border="0"> <tr> <td id="TOTAL" width="198"><input name="submit" type="submit" onclick="copytext('TOTAL', 'RESULT_TextField-3')" value="Click to proceed to Secure Page" /></td> <td width="529"> </td> </tr> </table> </div></td> </tr> </table> </form></CENTER> </body> </html>