Help me understand event handling in different browsers
December 6, 2012 6:07 PM   Subscribe

Question about Javascript, Backbone.js and clicking forms.

I'm working with some hastily-written Backbone.js code that's supposed to catch clicks from a form, and then respond to those clicks. But the event handling isn't working across different browsers.

The key line of contention is this:

eventType =;

Firefox says "event" isn't defined. As a newbie, I'm confused about how to make it see this event, which is bound to actions elsewhere in the code (in the View). Is there some standard way of doing this cross-browser, with jQuery, to make FF and IE alike deal well with this?

Any help much appreciated.
posted by steinsaltz to Computers & Internet (10 answers total) 1 user marked this as a favorite
I don't have time to dig into the code, but a few things:

1) You should absolutely be using jquery to be doing anything with js these days. It turns what used to be days of work into 5 minutes.

2) "event" is usually defined as a param of the function that is handling the event. So for example if you have:

$('.thingie').on('click', function() { //do things })

you can put the event as a param, like this:

$('.thingie').on('click', function(event) { //do things })

then use it inside the "do things" method. "Event" is not a magic reserved word, I usually just call it "e" but anything is fine, it will always be the first param of that event handler function.

Hope that helps!
posted by drjimmy11 at 6:10 PM on December 6, 2012

In this case, I'm not 100% sure b/c backbone annoys me but:

formEvent: function (event)

may do the trick.
posted by drjimmy11 at 6:11 PM on December 6, 2012 [1 favorite]

Thanks, it did do the trick. I think next time I'm going with Ember.js.
posted by steinsaltz at 6:15 PM on December 6, 2012


You're free to do whatever you want, but don't be afraid to just skip the fancier frameworks and just write jquery. it's super-fun and amazingly easy once you get into it. I work with js every day and frankly I find stuff like backbone to be massive overkill for all but the most complex projects.
posted by drjimmy11 at 6:19 PM on December 6, 2012

Yeah, I think you're right. I had nonstop fun with jQuery before I tried to MVC it.

(Question I wish I'd used my question on: If only I can make IE recognize
posted by steinsaltz at 6:27 PM on December 6, 2012

Yeah, Backbone gets a load of press at the moment, but I've developed with it and found it very awkward to use. It might help you to think of Backbone not as a framework but as a tool-kit instead. This is an interesting summary of some of the main players that you might find useful to guide your development strategy.
posted by urbanwhaleshark at 6:30 PM on December 6, 2012 [1 favorite]

An answer to your IE query?
posted by urbanwhaleshark at 6:33 PM on December 6, 2012

Bless you, thanks.
posted by steinsaltz at 6:36 PM on December 6, 2012

Yeah, as a toolkit, I like Backbone's model/collection stuff a lot, but other parts seem awkward.
posted by steinsaltz at 6:40 PM on December 6, 2012

You guys helped prevent a last-minute code crisis. Thanks so much.
posted by steinsaltz at 6:47 PM on December 6, 2012

« Older A belief system that denies itself.   |   Easy way to make a website accessible only by VPN? Newer »
This thread is closed to new comments.