Radio buttons change variable in JavaScript

Posted by dmanexe on Stack Overflow See other posts from Stack Overflow or by dmanexe
Published on 2010-04-02T16:40:36Z Indexed on 2010/04/02 16:43 UTC
Read the original article Hit count: 182

Filed under:
|

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;
        }

© Stack Overflow or respective owner

Related posts about html

Related posts about JavaScript