dropdown menu that changes values in subsequent fields

M

Mosher

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top