views:

51

answers:

3

Hi I would like to know if its possible to do something similar to the example shown below.

// Script A
$('.submitButton').click(function() {
   if (not valid) {
       $(this).attr("disabled", "disabled");
   }
});

// Script B
$('.submitButton').click(function() {
    // Do something else here
});

I would like to know whether you can actually stop the click event in Script B if not valid in Script A. The reason for the two events being separate is due to the fact that Script A will be used as a sort of a plugin module which will be inserted at the header of the page.

+1  A: 

Yes, you can call $(this).stopPropagation(); and then check for event.isPropagationStopped() in Script B.

read more @ http://api.jquery.com/event.stopPropagation/

ocdcoder
Thanks for your reply this solved my problem
Mark Buhagiar
A: 

use unbind. It will not fire the event again unless you bind it again

Teja Kantamneni
that seems really inefficient as he'd have to be binding and unbinding a lot afaik.
ocdcoder
A: 

Would this work for you?

$(".submitButton").click(function(event){
    event.preventDefault();
});
AndyC
no, that just prevents the browser from carrying out the normal actions, like an `<a>` tag from going to a site, or a submit from submitting the form.
ocdcoder
Ah right, thanks for that!
AndyC
no problem :-) read more @ http://api.jquery.com/event.preventDefault/ :-)
ocdcoder