[jQuery] Creating callable methods, and binding them to objects' actions.

[jQuery] Creating callable methods, and binding them to objects' actions.


Hi All,
I'm having a bit of a problem with selectors and binding in jQuery.
Basically I want to do 2 things:
1) create a javascript method callable by name that updates a div
2) bind that method to a set of radio buttons that runs the method on
change
It seems that none of the examples explicitly cover instances where
you roll your own methods. They all assume "function(){}" which I
personally consider messy.
That said, I have the following code thus far:
        <script type="text/javascript">
            $(document).ready(function(){
                function updateDonationTotal(){
                    var amount = $('#chargetotal').val();
                    var multiplier = 0;
                    var total = 0;
                    var donation_type = $("input:[@name:donation_type]:checked").val
();
                    var message = "";
                    //it's gonna be one of: donation_general, donation_stop_tab,
donation_pipe
                    switch(donation_type){
                        case 'donation_general': {multiplier = 1; break}
                        case 'donation_stop_tab': {multiplier = 500; break}
                        case 'donation_pipe': {multiplier = 100; break}
                    }
                    total = amount * multiplier;
                    message = "&nbsp; x " + multiplier + " = " + total;
                    $("#donation_total").html(message);
                    console.log(message);
                };
                $("input:[@id:chargetotal]").change(updateDonationTotal(););
            });
        </script>
The method 'updateDonationTotal' works fine. However, I receive
errors when trying to bind the method in various ways to the radio
buttons. I've tried 'bind', 'click', 'change'...all error out.
Please advise.
Best!