Javascript question. Auto calculate form fields

Pro
  • 114 points
    Serious WPMU DEV-ster
    I'm helpful
    Giovanni

    Member  —  3rd February 2012 (3 months ago)         

    This does not involve Wordpress I don't think but I need help.

    I have a form with two fields: Price and Quantity

    I would like to display dynamically the total based on the values of Price and Quantity.

    When the input to those fields are not Floats, just show N/A on the Total field. Ideally, the Total Field is not a form input readonly though and it's a span or <p> tag of some sort.

    Can someone please help? I've googled the hell out of it for like 3 hours and no luck.

    <table>
    <thead>
    <tr>
    <th>Each Gift</th><th style="margin-left:10px;">Quantity</th><th style="margin-left:10px;">Total gift amount</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>'.$mp->format_currency().'&nbsp;<input onkeyup="return ourhm_UpdateTotal(this,_mp_inventory)" class="toAdd" type="text" name="_mp_price" value="'.$price.'">
    </td>
    <td>
    <input class="toAdd" onkeyup="return ourhm_UpdateTotal(this,_mp_price)" style="margin-left:10px;" type="text" name="_mp_inventory" value="'.$inventory.'">
    </td>
    <td>
    <input readonly="readonly" id="totalgift" style="margin-left:10px;" type="text" name="totalgift" value="">
    </td>
    </tr>
    </tbody>
    </table>