Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have created a form using javascript, but now the problem is that the form should use the information inputted by the user on the form and generate a price. In order for this to happen I guess I have to create an Array/Table and be able to associate each selection with a price so when the user submits the form the Price would be generated, being the total sum of prices for each option selected...
Can anyone assist me with this I would really appreciate it.
Thanks in advance.

If you were to provide a link to the page you have so far I could give more detailed advice. But, here is what I can tell you for now:
Create an array within JS and just enter all the prices for the options in the same order that they exist in the select list. Example:
price1 = new Array (5.20,25.00,19.95)
You have multiple select lists. If each select list has different options, then you will need a different array for each. Just give them names that make sense to you.
You will need to create a field in which to store the total (for our examples let's say a text field with the name 'Total'). you can make this a hidden field if needed.
Then create a function to add all the prices and populate the total field:
function sumTotal() {
//Create shortcut to form element
var f = document.forms[0];
//Create the total variable
var totPrice = 0;
//Add the prices
totPrice += price1[o.select1.selectedIndex];
totPrice += price1[o.select2.selectedIndex];
totPrice += price1[o.select3.selectedIndex];
//Populate the total
o.Total.value = totPrice;
}I would call this function onChange of the select lists and onSubmit of the form.
Michael J

![]() |
Flash Animation Size
|
Meta Tags
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |