On Jan 9, 2014, at 8:21 AM, Frederick Cheung wrote: > In general people are moving away from explicit onchange functions. Instead > (using jquery) you'd do somthing like > > $('#a_select_box').on('change', function(){ > //this javascript is called when the drop down with id a_select_box is changed > })
Hear, hear! The primary advantage to this sort of construction is that you end up with fewer declared JavaScript functions in the global scope. This has tremendous benefits to page load speed and in-page performance, particularly on tiny devices with limited RAM. Prototype offers this sort of construction as well, and if you use the prototype_rails gem, you'll see that all of the helpers that make delete buttons work, and data-confirm attributes possible, all work there in exactly the same way, with no inline scripts littering the page. document.on('change', 'select.chained', function(evt, elm){ // do something with elm here whenever it changes // since this example is a class-based selector, you apply the // same behavior to all select tags that have the chained classname }); Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/91AE21A6-19D6-4CD3-A4B4-3249AFBC9774%40wdstudio.com. For more options, visit https://groups.google.com/groups/opt_out.