Forum Moderators: open
is it possible to get the following with javascript:
Mark checkbox 1, read the value and print out the value.
Mark checkbox 2, read the value, add them to the value from checkbox 1 and print the new sum out.
Unmark checkbox 1 ... and alter the sum.
(It is a lookalike for a shopping car but without submit-buttons!)
Thx a lot,
offler
1) write a function that reads the form, calculates the the total and updates a text field;
function sumForm(form)
{
if(form.checkbox1.checked) ...;
if(form.checkbox2.checked) ...;
...
form.total.value = ...;
}
2) add event handlers to the checkboxes;
<input type="checkbox" name="checkbox1" ... onClick="sumForm(this.form)" ...>
<input type="checkbox" name="checkbox2" ... onClick="sumForm(this.form)" ...>
<input type="text" name="total">
;)