Forum Moderators: open

Message Too Old, No Replies

Continuous updating

         

offler

7:56 am on Jul 28, 2005 (gmt 0)



Hi,

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

dcrombie

3:05 pm on Jul 28, 2005 (gmt 0)



I would approach this in two steps:

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">

;)