views:

108

answers:

1

Hi,

How would I be able to find out the caller/sender of an event on binding.

$(this).bind("submit", function(caller) { ... });

I found out that I could use "caller.originalEvent.explicitOriginalTarget", but this only works in firefox.

EDIT:

I'm using the jquery validation library from position-relative.net I want to make it so that if a button has a class called "bypass" on the sender, that makes the validation engine just return true so the form can be submitted. I.e. I'm using ASP.NET, and all button presses are postbacks (form submits). I'm just looking to make a back button.

I've added this code

if ((caller.originalEvent.explicitOriginalTarget != null) && (caller.originalEvent.explicitOriginalTarget.className == "bypass")) {
            return true; 
        }

on line 71, just under this line

$(this).bind("submit", function(caller) {   // ON FORM SUBMIT, CONTROL AJAX FUNCTION IF SPECIFIED ON DOCUMENT READY

Thoughts and suggestions appreciated.

Thanks

+1  A: 
T.J. Crowder
It seems like I do not have that member.These are all the members I see available.http://img836.imageshack.us/img836/2240/clipboard02kq.jpg
Mike
@Mike: That's very strange, you should have it if you're using jQuery. jQuery normalizes the event object for you. I've tested the above on IE6 and IE8 on Windows, and Chrome, Opera, and Firefox on Linux. All fine. If you post some further code we may be able to help you figure out what's going wrong.
T.J. Crowder
I'm using jQuery, with the Validation Engine from position-relative.net I'm trying to modify the jquery.validationEngine.js so that if a button has a "bypass" class on it, the validation engine will return true on the form to allow it to postback.
Mike
target seems to be the actual form itself. Still can't find the sender :-(
Mike
@Mike: Ah! Okay, I don't think anyone here understood what you meant by "sender" in that context. You can't do that with the form `submit` event. Instead, you need to hook the `click` event on the submit button and set a flag (either a flag in code somewhere or a hidden field on the form). If I get a chance, I'll do an example in a little bit.
T.J. Crowder
That would be very much appreciated. I've tried to change the validationEngine.js code to a $(".submitbutton").bind("click" etc.. but it does not want to fire anymore, and all the logic that was in the $(this).bind("submit", function) is referencing "this", which is not the form anymore. Aragh!
Mike
@Mike: Updated.
T.J. Crowder
Thank you so much. Your answer is the best I have ever seen on stack overflow. Your help is so greatly appreciated. It's help like this that makes the programming community thrive. I have learned so much more over the weekend regarding jQuery and html forms, which has resulted from your answer! You are a legend, Sir!
Mike