Why does this JavaScript not correctly update input values?
        Posted  
        
            by dmanexe
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by dmanexe
        
        
        
        Published on 2010-04-09T18:29:36Z
        Indexed on 
            2010/04/09
            18:33 UTC
        
        
        Read the original article
        Hit count: 358
        
I have two input fields, and without changing their names (i.e., I have to use the name with the brackets), how do I make this javascript code work?
<script>
    function calc_concreteprice(mainform) {
        var oprice;
        var ototal;
        oprice = (eval(mainform.'estimate[concrete][sqft]'.value) * eval(mainform.'estimate[concrete][price]'.value));
        ototal = (oprice);
        mainform.'estimate[concrete][quick_total]'.value = ototal;
    }   
</script>
Here's the HTML of the input area.
<tr>
                        <td>Concrete Base Price</td>
                        <td><input type="text" name="concrete[concrete][price]" value="" class="item_mult" onBlur="calc_concreteprice(document.forms.mainform);" /> per SF <strong>times</strong> <input type="text" name="concrete[concrete][sqft]" value="" class="item_mult" onBlur="calc_concreteprice(document.forms.mainform);" /> SF</td>
                        <td> = <input type="text" name="concrete[concrete][quick_total]" value="" /></td>
                    </tr>
I know I can get it working by changing_the_input_name_with_underscores but I need to have the names with the brackets (storing the form contents in an array).
© Stack Overflow or respective owner