3

I'm using JQuery to intercept a form, but it's not working in any version of IE. Does anyone have any tips? I tried form.submit() but found it to have problems in Firefox. Any help would be greatly appreciated.

$(document).ready(function() {
    $("form").submit(function(e) {
        if (e.originalEvent.explicitOriginalTarget.id == "myButton") {
            if (some status is true continue to submit the form)
                return true;
                //If the status above is false continue to prompt the user if they want to submit or not
            var ok = confirm('Do you really want to save your data?');
            if (ok) {                
                return true;
            }
            else {
                //Prevent the submit event and remain on the screen
                e.preventDefault();
                return false;
            }
        }
    });

    return;
});
kprobst
  • 16,165
  • 5
  • 32
  • 53
JCraine
  • 1,159
  • 2
  • 20
  • 38
  • 1
    Is `e.originalEvent.explicitOriginalTarget` available in IE? – alex Jul 20 '12 at 04:56
  • 1
    `e.explicitOriginalTarget` is Mozilla-specific. – Ram Jul 20 '12 at 05:03
  • I'm not using that code specifically, but very similar. Just a return true for sending the form, and preventing the default if there's an error. – JCraine Jul 20 '12 at 05:05
  • Try e.stopPropogation or check http://stackoverflow.com/questions/4479216/does-internet-explorer-supports-e-preventdefault – Ankit Jul 20 '12 at 05:08
  • Do you have any input element with name "submit", this might be problem – Sudesh Jul 20 '12 at 05:15

1 Answers1

0

Have you attempted to attach to the click event of the buttons instead in some way? I've picked an arbitrary selector in the example here.

$(".submit").click(function(e) {
    if (e.target.id === "go1") {
        alert("we're good!");
        return true;
    }

    e.preventDefault();
    return false;
});

Here's a jsfiddle: http://jsfiddle.net/qRbQe/

Since e.originalEvent.explicitOriginalTarget is Mozilla-specific and intended to be used by plug-in developers not Web app developers, I don't think there is a way to do it given that you don't get the element that triggered the event when handling the submit event.

Sumo
  • 4,066
  • 23
  • 40