How do I make JavaScript to set these element values?

Posted by dmanexe on Stack Overflow See other posts from Stack Overflow or by dmanexe
Published on 2010-04-05T22:53:54Z Indexed on 2010/04/05 23:03 UTC
Read the original article Hit count: 171

Filed under:
|
|
|

I have two fields that need to multiply each other and fill a 3rd form's value. Here's the HTML:

    <input type="text" name="estimate[concrete][price]" value="" onBlur="calc_concreteprice(document.forms.mainform);" /> 
per SF <strong>times</strong> 
<input type="text" name="estimate[concrete][sqft]" value="" onBlur="calc_concreteprice(document.forms.mainform);" /> SF
 = <input type="text" name="estimate[concrete][quick_total]" value="" />

Here's my JavaScript:

    function calc_concreteprice(mainform) {
        var oprice;
        var ototal;

        oprice = ((mainform.estimate[concrete][sqft].value) * (mainform.estimate[concrete][price].value));
        ototal = (oprice);

        mainform.estimate[concrete][quick_total].value = ototal;
    }

I want the first two forms to be multiplied together and output to the third. I think my problem may be within how I am referencing the input field names, with brackets (I'm taking results from this form as an array so I'm already used to working with the results as a multi-dimensional array).

Thanks for the help!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html