Dynamic updates with variable checkboxes

Discussion in 'JavaScript' started by wdillsmith, Nov 23, 2008.

  1. #1
    I have what seems like an easy question but my lack of Javascript knowledge means I've spent a couple hours and still can't figure it out. I'm hoping somewhere here will know the answer.

    I am trying to write an HTML form to reconcile an invoice. Each record will have a unique order number, along with an amount. What I would like to do is have a running total calculated as checkboxes are clicked so that the person clicking knows the values of the selected orders so far. A given invoice could have several hundred records. I need the names of the checkboxes to all be different because once the user hits submit, I'll need to pull the invoice numbers from the submitted form to know which records to mark as "reconciled." Here is an example of what the form would look like, without the fancy javascript:

    Invoice: 123
    Date: November 22, 2008
    Total Amount: $3,023.64
    <form method="post" action="submitInvoice.php">
    <input type="checkbox" name="Order1" value="15.00"> Order 1<br>
    <input type="checkbox" name="Order2" value="10.00"> Order 2<br>
    <input type="checkbox" name="Order3" value="123.11"> Order 3<br>
    <input type="hidden" name="total" value="3023.64">
    PRINT RUNNING TOTAL HERE
    PRINT DIFFERENCE HERE
    <input type="submit" name="doSubmit" value="Finished">

    So as each checkbox is checked (or unchecked), the RUNNING TOTAL would update on the screen.

    As an added bonus, it would be fabulous if I could also show the amount difference between the current running total and the amount of the invoice. I would know the invoice total ahead of time so I could stick it in a hidden field as shown above for instance.

    Any help would be greatly appreciated. Thanks,

    Bill
     
    wdillsmith, Nov 23, 2008 IP