indianagreg
01-05-2011, 02:14 PM
I'm a js noob but have managed to cobble together some code for a simple calculator. All the math works well, but changing the radio button doesn't have any effect. Basically, I have 4 set of equations (long if/then statements) - 2 are to be used when one radio button is checked, 2 if the other is checked.
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<script language="JavaScript">
function temp(form)
{
var r1 = form.r1.value;
var GNW = parseFloat(form.GNW.value, 10);
var BNW = parseFloat(form.BNW.value, 10);
var totalfee = 0;
var netfee = 0;
var discount = 0;
//if the "old" radio button is selected, use the the next two if/then formulas
if (r1=1)
{
for brevity sake, I'll omit the first two if/then equations
//close out the "old" options
}
//use the "new" option
else if (r1=2)
{
// two more if/then statements
}
// this applies to all conditions
discount = totalfee - netfee;
form.totalfee.value = totalfee/4;
form.netfee.value = netfee/4;
form.discount.value = discount/4;
}
and now the radio buttons
<input name="r1" value=1 type="radio" checked="checked">Old (3m/3m)
<input name="r1" value=2 type="radio" >Current (5m/5m)</p><p>
hopefully the brevity makes the answer apparent, the full code is attached if I've left out a crucial detail.
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<script language="JavaScript">
function temp(form)
{
var r1 = form.r1.value;
var GNW = parseFloat(form.GNW.value, 10);
var BNW = parseFloat(form.BNW.value, 10);
var totalfee = 0;
var netfee = 0;
var discount = 0;
//if the "old" radio button is selected, use the the next two if/then formulas
if (r1=1)
{
for brevity sake, I'll omit the first two if/then equations
//close out the "old" options
}
//use the "new" option
else if (r1=2)
{
// two more if/then statements
}
// this applies to all conditions
discount = totalfee - netfee;
form.totalfee.value = totalfee/4;
form.netfee.value = netfee/4;
form.discount.value = discount/4;
}
and now the radio buttons
<input name="r1" value=1 type="radio" checked="checked">Old (3m/3m)
<input name="r1" value=2 type="radio" >Current (5m/5m)</p><p>
hopefully the brevity makes the answer apparent, the full code is attached if I've left out a crucial detail.