0

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;
        }
1
  • ((mainform.estimate_pool_width.value) + (mainform.estimate_pool_length.value) * (mainform.estimate_pool_shape.value)) bugs out Commented Apr 2, 2010 at 17:10

1 Answer 1

1
var estimate_pool_shape = 0; // Or some default value.  Maybe 1?
for(var i = 0; i < mainform.estimate_pool_shape.length;i++){
 if(mainform.estimate_pool_shape[i].checked){
   estimate_pool_shape = mainform.estimate_pool_shape[i].value;
   break;
 }
}

Should give you what you need.

Sign up to request clarification or add additional context in comments.

3 Comments

Above the line with %%%RADIO BUTTON VARIABLE HERE%%% Then replace %%%RADIO BUTTON VARIABLE HERE%%% with estimate_pool_shape
Returns NaN to the target field
Sorry I made some mistakes in the code above, I'll edit it so its right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.