Missed the colon, the single quotes should be OK; the jQuery docs' example even uses them: $("input[name='newsletter']")
On Feb 19, 12:11 am, Ricardo Tomasi <ricardob...@gmail.com> wrote: > I don't think you need the colon in there (nor the single quotes) > > $("input[name=donation_type]") > > On Feb 19, 4:04 am, mkmanning <michaell...@gmail.com> wrote: > > > You shouldn't have to refer to the same object in different ways, $ > > ("input:[name='donation_type']") will work for both getting the value > > and binding an event. > > The "@" before the attribute name was deprecated as of version 1.2 > > > On Feb 18, 9:51 pm, gberz3 <gbe...@gmail.com> wrote: > > > > Ok, I got it to work using the following: > > > > $("#chargetotal").change(updateDonationTotal); > > > $("input:[name='donation_type']").change(updateDonationTotal); > > > > I mistakenly posted chargetotal as the radio when it was actually a > > > text field. That said, what is the difference between the following > > > items: > > > > var donation_type = $("input:[...@name:donation_type]:checked").val(); > > > $("input:[name='donation_type']").change(updateDonationTotal); > > > > It doesn't seem very intuitive to have to refer to the same item in > > > different ways in order to get different results. I should be able to > > > say "GET OBJECT where NAME EQUALS" regardless of whether I'm looking > > > for its value or to bind to one of its methods. Can someone shed some > > > light on why I must call each of these methods on the input in the > > > different manners? > > > > Thanks. > > > On Feb 18, 7:10 pm, mkmanning <michaell...@gmail.com> wrote: > > > > > try: > > > > $("input:[...@id:chargetotal]").change(updateDonationTotal); > > > > > On Feb 18, 1:55 pm, gberz3 <gbe...@gmail.com> wrote: > > > > > > 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 = " 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!