dropdown menu that changes values in subsequent fields

Discussion in 'Javascript' started by Mosher, May 27, 2005.

  1. Mosher

    Mosher Guest

    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>Motorcycle</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:<input type=text name=final_amount
    size=10>
    </form>
    <!-- end of code --!>

    Explanation: So, what will be auto calculated is the "final_amount" 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
     
    Mosher, May 27, 2005
    #1
    1. Advertising

  2. Mosher

    RobG Guest

    Mosher wrote:
    > 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:
    >


    Have a look through Matt Kruze's stuff here:

    <URL:http://www.mattkruse.com/javascript/dynamicoptionlist/>

    [...]

    --
    Rob
     
    RobG, May 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Breakspear
    Replies:
    0
    Views:
    439
    Ryan Breakspear
    Nov 18, 2003
  2. Miguel Dias Moura
    Replies:
    3
    Views:
    4,310
    Bruno Sirianni
    Apr 3, 2004
  3. Mike
    Replies:
    1
    Views:
    812
  4. Piotrek \Alchemik\
    Replies:
    0
    Views:
    309
    Piotrek \Alchemik\
    Nov 12, 2006
  5. Replies:
    0
    Views:
    95
Loading...

Share This Page