I am trying to create an if statement in this calculator that does the following
if(radiobutton1 == selected) {
AddDecimal(((STotal) * 10) / 12);}
else { (AddDecimal(STotal));
}
I am new to javascript and what i have is not working. the radio button names are r1 and r2.
you can see what i have at [URL=http://www.fivecubed.com/web_hosting/estimate.html]http://www.fivecubed.com/web_hosting/estimate.html
<SCRIPT LANGUAGE=”JavaScript”>
<!– hide from old browsers –>
var SAmt1 = 0.00,SAmt2 = 0.00,SAmt3= 0.00,SAmt4 = 0.00,SAmt5 = 0.00,SAmt6= 0.00;
var STax = 0.00,SSubTotal = 0.00,STotal = 0.00;
var Item1 =””,Item2 = “”,Item3 = “”,Item4 =””,Item5 = “”,Item6 = “”;
var SShipping = 0;
/*****************
function AddDecimal(number) {
var withdecimal = “”;
var num = “” + number;
if (num.length == 0) {
withdecimal += “0”;
} else if (num.length == 1) {
withdecimal += “0.0” + num;
} else if (num.length == 2) {
withdecimal += “0.” + num;
} else {
withdecimal += num.substring(0, num.length – 2);
withdecimal += “.”
withdecimal += num.substring(num.length – 2, num.length);
}
return withdecimal;
}
function compute(form)
{
SAmt1 = Math.round(eval(form.Item1.value * 10));
SAmt2 = Math.round(eval(form.Item2.value
SAmt3 = Math.round(eval(form.Item3.value * 100));
SAmt4 = Math.round(eval(form.Item4.value
SAmt5 = Math.round(eval(form.Item5.value * 50));
SAmt6 = Math.round(eval(form.Item6.value
SShipping = 00;
SShipping = Math.round(SShipping);
SSubTotal =(SAmt1 + SAmt2 + SAmt3 + SAmt4 + SAmt5 + SAmt6 + SShipping);
STotal =SSubTotal + STax;
form.Amt1.value = AddDecimal(SAmt1);
form.Amt2.value = AddDecimal(SAmt2);
form.Amt3.value = AddDecimal(SAmt3);
form.Amt4.value = AddDecimal(SAmt4);
form.Amt5.value = AddDecimal(SAmt5);
form.Amt6.value = AddDecimal(SAmt6);
form.SubTotal.value = AddDecimal(SSubTotal);
form.Total.value = if(r1 == selected) {
AddDecimal(((STotal) * 10) / 12);}
else { (AddDecimal(STotal));
}
}
function ClearForm(form)
{form.Item1.value = “”;
form.Item2.value = “”;
form.Item3.value = “”;
form.Item4.value = “”;
form.Item5.value = “”;
form.Item6.value = “”;
SShipping = 0;
form.Shipping.value = 0;
SSubTotal = 0;
form.SubTotal.value = 0;
SAmt1 = 0;
form.Amt1.value = 0;
SAmt2 = 0;
form.Amt2.value = 0;
SAmt3 = 0;
form.Amt3.value = 0;
SAmt4 = 0;
form.Amt4.value = 0;
SAmt5 = 0;
form.Amt5.value = 0;
SAmt6 = 0;
form.Amt6.value = 0;
SShipping = 0;
form.Shipping.value = 0
SSubTotal = 0;
form.SubTotal.value = 0;
STotal = 0;
form.Total.value = 0;
}
<!– done hiding from old browsers –>
</SCRIPT>