dimanche 29 octobre 2017

Computing Total Value of Checkbox Selections

I am trying to figure out the best way to compute a total value based on selection of a combination of 5 different selections using checkboxes. Here is code example:

<input type="checkbox" value="Value 1" name="Value1" id="Value1">Value 1
<input type="checkbox" value="Value 2" name="Value2" id="Value2">Value 2
<input type="checkbox" value="Value 3" name="Value3" id="Value1">Value 3
<input type="checkbox" value="Value 4" name="Value4" id="Value1">Value 4
<input type="checkbox" value="Value 5" name="Value5" id="Value1">Value 5
<input type="checkbox" value="Total Value" name="TotalValue"
id="TotalValue">Total Value

Here are sample number values of the checkboxes: Checkbox 1 - 100 Checkbox 2 - 125 Checkbox 3 - 150 Checkbox 4 - 175 Checkbox 5 - 200

So my goal is to come up with a number value for TotalValue based on the checkbox selections. For example, if Checkbox 2 and Checkbox 4 are selected, Total Value would be 300. So user can select a single checkbox or any combination of checkboxes. I could probably do it using javascript, but the code would be very cumbersome and long. So was wondering if there is a streamlined way to do it using jQuery. Any help would be greatly appreciated. Thank you.




Aucun commentaire:

Enregistrer un commentaire