Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Correctly passing a radio button value

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.

Code:
```<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

Code:
```//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;
}```
Code:
```<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.

• The compare operator is ==
Code:
```if(r1==1) {
...
}```

• ## Users who have thanked devnull69 for this post:

indianagreg (01-05-2011)

• devnull69,
Thanks for the quick reply. When I make that change, the whole script stops working (it just returns zeros).

If I set the value of the radio button to words vs. numbers, will that make a difference?

Code:
```<input name="r1" value="old" type="radio" checked="checked">Old (3m/3m)
<input name="r1" value="new" type="radio" >Current (5m/5m)</p><p>```
and then use
Code:
```if(r1 == "old) {
...
}```

• figured it out. used
Code:
`if (form.r1[0].checked)`
instead of the r1 value stuff.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•