On Oct 6, 12:06 am, lesmith <[EMAIL PROTECTED]> wrote:
> Hello Peeps.
>
> Hope you can advice me on how to do this. Im new to prototype so
> please be gentle.
>
> I currently have a form where clients can see a list of invoices. They
> can select a set of invoices via checkbox and hit the pay button thus
> sending them to a page which gives a total.
>
> I would now like to make this better by giving them a value before
> they hit submit.
>
> Currenty this is an example of my checkbox data.
>
> <input name="invoiveID[]" value="<?=$invoiceID?>" type="checkbox" />
>
> How can I make it so when they select a check box they are given a
> running total so they know the total cost before submitting.
>
> I have seen a few example where you can add checkbox data but my
> values contain invoiceID.
>
> Hope you can advice.
>
> Thank you in advance
You haven't given us a lot of information, but I'm guessing that
you're displaying the value of the invoice in another DOM element -
say a <span>. (If not, you'll need to make an Ajax query to get the
value of the invoice.
I'm assuming that your page is structured so that the value is in some
structure - say a div - with the checkbox. (Alternatively you might
identify them by id (have the id of the <span> related in a standard
way to that of the checkbox. But with Prototype I find traversing the
DOM easier than manipulating ID's).
This is untested, and I've probably got some details wrong, but it
should give you the idea:
var totalValue = 0;
var allCheckboxes = $$('input[type='checkbox'].invoice);
function addToTotal(checkbox) {
var valuespan = checkbox.up('div').down('span.value');
var value = Number(valuespan.firstChild.data);
totalValue += value;
};
function updateTotal() {
allCheckboxes.findAll(function(box) {return
box.checked;}).each(addToTotal);
}
allCheckboxes.invoke('observe', 'change', updateTotal);
Colin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---