dropdown menu that changes values in subsequent fields

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mosher

    dropdown menu that changes values in subsequent fields

    Hi all, I am looking for some event handler auto-calc help on a form that
    takes user input through text fields and dropdown menus. I would like some
    of the text fields to be auto populated when dropdown menu selections are
    made. Here is an abstract html/javascript form:

    <form>
    Enter how much money you are willing to spend:<input type=text name=amount
    size=10>
    Enter your home city:
    <select name=city>
    <option selected value=0>Choose city:</option>
    <option value=ny>New York</option>
    <option value=la>Los Angeles</option>
    </select>

    Enter what you want to buy:
    <select name=type>
    <option selected value=0>Choose type:</option>
    <option value=car>Car</option>
    <option value=moto>Moto rcycle</option>
    </select>

    <script = javascript>
    <!-- This is where the javascript computations will be - this is not full JS
    code but what would be needed --!>
    var car=15000
    var moto=7000
    var ny_fees= .10
    var la_fees= .07

    if (city = ny) and (type = car) {
    populate the "total" field with the computation of: total = (car + (car
    * ny_fees));
    } else if (city = la) && (type = car) {
    populate the "total" field with the computation of: total = (car + (car
    * la_fees));
    } else {
    city is not ny or la and total is just the total
    }
    final_amount = amount - total_fees;
    <!-- All computations will be calculated via an event handler (pehaps an
    "onchange" handler?) on the dropdown menu(s) --!>
    </javascript>

    This is the total that you will pay: <input type=text name=total size=10>

    This is how much money you have remaining:<inpu t type=text name=final_amou nt
    size=10>
    </form>
    <!-- end of code --!>

    Explanation: So, what will be auto calculated is the "final_amou nt" and
    "total" fields based on the two drop down menu selections above. The form
    data will then be sent to a cgi form processing script.

    Any ideas? Thanks in advance!

    Mosher


  • RobG

    #2
    Re: dropdown menu that changes values in subsequent fields

    Mosher wrote:[color=blue]
    > Hi all, I am looking for some event handler auto-calc help on a form that
    > takes user input through text fields and dropdown menus. I would like some
    > of the text fields to be auto populated when dropdown menu selections are
    > made. Here is an abstract html/javascript form:
    >[/color]

    Have a look through Matt Kruze's stuff here:

    <URL:http://www.mattkruse.c om/javascript/dynamicoptionli st/>

    [...]

    --
    Rob

    Comment

    Working...