PDA

View Full Version : Better Order Form but doesn't work



cardnexus
09-21-2006, 07:36 PM
This order form can only works when you pick just one item.
If you select one radio button in one row, it displays total and unit price.
However, if you select another botton in another row (either below or above), the total won't show.
Can someone help me with this?
:confused:
<SCRIPT LANGUAGE="JavaScript">

function ComputeTotal(form){
//Profit calculator
Profit_rate1 = 1 + 0.12; // change the profit %
Profit_rate2 = 1 + 0.10; // change the profit %
Profit_rate3 = 1 + 0.11; // change the profit %
Profit_rate4 = 1 + 0.20; // change the profit %
Profit_rate5 = 1 + 0.07; // change the profit %
var indexCPU = null;
var indexMAB = null;
var CPU = 0;
var MAB = 0;
for(i=0;i<3;i++){
if(document.forms[0].CPU[i].checked){indexCPU = i;}
if(document.forms[0].Mainboard[i].checked){indexMAB = i;}
}
if(indexCPU!=null){
CPU = formatCurrency(form.CPU[indexCPU].value*Profit_rate1);
}
if(indexMAB!=null){
MAB = formatCurrency(form.Mainboard[indexMAB].value*Profit_rate2);
}
form.CPU1.value = formatCurrency(CPU);
form.Mainboard1.value = formatCurrency(MAB);

var subtotal1 = CPU + MAB ;
form.subtotal1.value = formatCurrency(subtotal1);
var savevalue = subtotal1 * form.disrate.value;
var subtotal2 = form.subtotal1.value - savevalue;
form.subtotal2.value = formatCurrency(subtotal2);
var tax1 = subtotal2 / 100 * form.taxrate.value;
form.tax.value = formatCurrency(tax1);
form.total.value = formatCurrency(subtotal2 + tax1);
}

function formatCurrency(num){
var num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)){num = "0";}
var sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
var cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10){cents = "0" + cents;}
for(i=0; i<Math.floor((num.length-(1+i))/3); i++){
num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
}
return (((sign)?'':'-') + num + '.' + cents);
}
</SCRIPT>

<body>

<BODY BGCOLOR="#F8F8FF">

<FORM
METHOD="POST"
ACTION="mailto:email@address.com?subject=Computer System">
<table width="591" border="1">
<tr>
<td width="535">

<input type="radio" value=30 name="CPU" onClick="ComputeTotal(this.form)">
<input type="radio" value=40 name="CPU" onClick="ComputeTotal(this.form)">
<input type="radio" value=50 name="CPU" onClick="ComputeTotal(this.form)">

</td>
<td width="40">
<input type="TEXT" size=6 name="CPU1" maxlength="6">
</td>
</tr>
<tr>
<td width="535">



<input type="radio" value=30 name="Mainboard" onClick="ComputeTotal(this.form)">
<input type="radio" value=40 name="Mainboard" onClick="ComputeTotal(this.form)">
<input type="radio" value=50 name="Mainboard" onClick="ComputeTotal(this.form)">

</td>
<td width="40">
<input type="TEXT" size=6 name="Mainboard1" maxlength="6">
</td>
</tr>




<tr>
<td width="535">
<p align="right"> <b>SUBTOTAL1: </b>
</td>
<td width="40"><b>
<input type="TEXT" size=6 name="subtotal1" maxlength="6">
</b></td>
</tr>
<tr>
<td width="535">
<p align="right">
<p align="right"><b>Discount Rate: </b>
<select name="disrate" onChange="ComputeTotal(this.form)">
<option value="0.00">0%</option>
<option value="0.01">1%</option>
<option value="0.02">2%</option>
<option value="0.03">3%</option>
<option value="0.04">4%</option>
<option value="0.05">5%</option>
<option value="0.06">6%</option>
<option value="0.07">7%</option>
<option value="0.08">8%</option>
<option value="0.09">9%</option>
<option value="0.10">10%</option>


<b>SUBTOTAL2:</b>
</td>
<td width="40">
<input type="number" size=6 name="subtotal2" maxlength="6">
</td>
</tr>
<tr>
<td width="535">
<div align="right"><b>TAX:</b><input type="number" size=3 name="taxrate" value="8.25"></div>
</td>
<td width="40">
<input type="number" size=6 name="tax" maxlength="6">
</td>
</tr>
<tr>
<td width="535">
<p align="right">
<p align="right"><b>Total: </b></p>
</td>
<td width="40">
<input type="number" size=6 name="total" maxlength="6">
</td>
</tr>
</table>
<p>&nbsp;</p>


</form></BODY></HTML>


<!-- Simba says Roar. -->