Radio buttons change variable in JavaScript
- by dmanexe
I have two fields which calculate a total, but I have a radio button pair that determines a variable within the equation. Here's the radio button code:
<input type="radio" name="estimate_pool_shape" value="1" /> Angle
<input type="radio" name="estimate_pool_shape" value=".86392" /> Freeform
Immediately after that, this JavaScript is then calculating the surface area of the pool based of these fields and script:
(Length <input type="text" size="5" name="estimate_pool_length"
onBlur="conv2inches(document.forms.mainform);" />) x
(Width <input type="text" name="estimate_pool_width" size="5"
onBlur="conv2inches(document.forms.mainform);" />)
The following JavaScript already works to update the fields, I just need the variable it uses to set the field values to change based on the radio buttons.
function conv2inches(mainform) {
var oin;
var oinches;
if(isNaN(mainform.estimate_pool_width.value)||isNaN(mainform.estimate_pool_length.value)){
alert("Please enter numbers only");
return false;
}
oin = ((mainform.estimate_pool_width.value) + (mainform.estimate_pool_length.value) * %%%RADIO BUTTON VARIABLE HERE%%%);
oinches = (oin);
if(oinches==0){
alert("Please enter valid values into the boxes");
}
mainform.estimate_pool_sqft.value = oinches;
return false;
}