Sum of multiple dropdown value selections - guidance would be appreciated
Not a seasonsed JS user; I would like to have a number of dropdown forms on a page and have JS sum the total value up as the user makes their way down the page and selects values. I've googled the daylights out of this and come up with a proof of concept below - if I could get it to work right, I would apply to a larger page. It will live on a Sharepoint server so I can't just use PHP to handle the summing. Any help on my shortcomings would be greatly appreciated:
var sum = 0;
sum = sum + value;
<select name=select1 onchange='OnChange(select1)'>
<select name=select2 onchange='OnChange(select2)'>
Hmmm...one other thing....
One follow-up question; I notice that if I change a dropdown's value more than once, the function just keeps adding it up and I end up with a score greater than the possible total for the whole page. Is there a reasonable way of handling an event such as this?
Appending listbox values prior to Submit
Tirna or anyone else here,
My form sends data to a third party site, which limits the number and types of fields I can use for form submission. So the processing has to be client-side. The listbox could have 50 to 100 options that regularly change. I want to concatenate the selected values for the external service. That way I only have one field on the service where I can search on "dog" and find all records with that value regardless of whether it was the only selection option or one of several.
What I need in particular -- I'm open to any solution:
1. A multidimensional array of listbox option values that represent the HTML text (must be defined) and option values (optional, if not provided the value is the same as the text) for each listbox.
2. A form with listbox where the user can select multiple options.
3. When the form is submitted:
A. The selected items are concatenated with a space, like "cat dog pig"
B. The concatenated string is sent as the value for the listbox field.