radi8
radi8

Reputation: 526

Alternative to Mozilla 'explicitOriginalTarget' for cross browser functionality

I have a fiddle at: http://jsfiddle.net/radi8/Nt556/1/

This class will bind a listener to all of the 'submit' buttons on a form. When the user clicks on one of the buttons, the class function will process it as necessary. I originally developed this class using FireFox and using the: var btnName = event.originalEvent.explicitOriginalTarget.defaultValue; works great therein, but I later found that this is a Mozilla only function.

Can anyone offer an alternative for IE and Chrome?

my class:

    var RequiredField = {
    init: function() {
        var theForm = document.getElementsByTagName("form");
        $(theForm).bind("submit", RequiredField.submitListener);
    },

    submitListener: function(event) {
        event.preventDefault();
        var btnName = event.originalEvent.explicitOriginalTarget.defaultValue;
        if (btnName == 'Process Route') {
            processType = 0;
            alert('Process');
        }
        else if (btnName == 'Finalize Route') {
            processType = 1;
            alert('Finalize');
        }
        else {
            processType = 99;
        }
        try {

        }
        catch (e) {
            event.preventDefault();
        }
    }
};
RequiredField.init();

Upvotes: 3

Views: 1197

Answers (1)

Pointy
Pointy

Reputation: 413826

I'd just bind "click" for the form:

  $('form').delegate(':submit', 'click', RequiredField.submitListener);

Then the target of the event will be the button directly.

Upvotes: 1

Related Questions