#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Los Angeles, CA
    Posts
    85
    Rep Power
    13

    Javascript - How to add up values of field into another ?


    ok lets say I have a form with 3 input boxes (Small, Medium, Large) and then on the right another input box labeled "total".

    A small is 1.99 a medium is 2.99 and a large is 3.99

    Now you can choose how many you want of each so If I want 1 small and 2 mediums... in the total box I want that to update with the total price value = $7.97 automatically when they tab out.

    What kind of javascript coding does this? I've tried looking around but I have no idea what to look around for thanks all!
    ~jim~
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    135
    Rep Power
    12
    Code:
    <form name="form3">
    <input type="text" size="5" name="small" onKeyUp="document.form3.total.value=parseInt(document.form3.small.value)+parseInt(document.form3.medium.value)+parseInt(document.form3.large.value)">
    +
    <input type="text" size="5" name="medium" onKeyUp="document.form3.total.value=parseInt(document.form3.small.value)+parseInt(document.form3.medium.value)+parseInt(document.form3.large.value)">
    +
    <input type="text" size="5" name="large" onKeyUp="document.form3.total.value=parseInt(document.form3.small.value)+parseInt(document.form3.medium.value)+parseInt(document.form3.large.value)">
    =
    <input type="text" size="6"  name="total" onKeyUp="document.form3.total.value=parseInt(document.form3.small.value)+parseInt(document.form3.medium.value)+parseInt(document.form3.large.value)">
    </form>

IMN logo majestic logo threadwatch logo seochat tools logo