A lil bit of Java Script
Posted: Wed Feb 04, 2009 3:01 pm
I know this board is for PHP .. I know, but my boss is requiring me to use it... so anyone HELP?
The total just keeps coming up 0.00
Here is the lovely HTML!
Here is the JavaScript:
The total just keeps coming up 0.00
Here is the lovely HTML!
Code: Select all
Pick an ad:
<input type="radio" name="advertise" id="advertise" onChange="price_form()" value="250.00"> 1/4 Page
<input type="radio" name="advertise" id="advertise" onChange="price_form()" value="500.00"> 1/2 Page
<input type="radio" name="advertise" id="advertise" onChange="price_form()" value="750.00"> 3/4 Page
<input type="radio" name="advertise" id="advertise" onChange="price_form()" value="1250.00"> Full Page
How many issues:
<input type="radio" name="numberofissues" id="numberofissues" value="1" onChange="price_form()"> 1
<input type="radio" name="numberofissues" id="numberofissues" value="2" onChange="price_form()"> 2
<input type="radio" name="numberofissues" id="numberofissues" value="3" onChange="price_form()"> 3
<input type="radio" name="numberofissues" id="numberofissues" value="4" onChange="price_form()"> 4
*A 3% online processing fee is added to the price of your order.
Subtotal: <input name="grandtotal" type="text" id="grandtotal" size="8" maxlength="8" readonly="true">
Grand Total: <input name="cctotal" type="text" id="cctotal" size="8" maxlength="8" readonly="true">
Code: Select all
<script language="JavaScript">
function price_form() {
var grandtotal = 0;
var advertise = document.adform.advertise.value
var numberofissues = document.adform.numberofissues.value
if(numberofissues > 0){
grandtotal = numberofissues * advertise
grandtotal = formatCurrency(grandtotal);
document.adform.grandtotal.value = grandtotal;
}else{
document.adform.grandtotal.value = 0;
}
cctotal = grandtotal * 1.03; // add 3 % to all orders
cctotal = formatCurrency(cctotal);
document.adform.cctotal.value = cctotal;
grandtotal = formatCurrency(grandtotal);
document.adform.grandtotal.value = grandtotal;
}
function formatCurrency(num) {
num = !isNaN(num) ? Math.round(num * 100) / 100 : 0;
num.toString().indexOf(".") == -1 ? num += ".00" : void 0;
while(/\.\d{0,1}$/.test(num)) num += "0";
return num; }
</script>