I've a textbox having focusout event on it. whenever the textbox loses focus (Tab, mouse click on any other part of the form),based on certain conditions a user-written function disaplying an alert is called.
Now, my form also has a button, after filling the textbox when i click the button focusOut event of textbox is called instead of the button click event.
how do i stop the foucusout event of the textbox being called on button click ?
("$textbox").focusout(function(){
validation;
alert("message");
});
("$btn").click(function(){
----
});
can any one help me?
I've changed your click event to a mousedown (so it fires first) and used a variable to track your click :
var buttonClicked = false;
$('#txt1').focusout(function(){
if(!(buttonClicked)){
alert('BlurEvent');
}else{
buttonClicked = false;
}
});
$('#btn').mousedown(function(event){
alert('ClickEvent');
buttonClicked = true;
});
http://jsfiddle.net/924SZ/
EDIT
var buttonClicked = false;
$('#txt1').focusout(function(){
if(!(buttonClicked)){
// do normal focusout code.
}else{
// button was clicked - dont execute some code.
buttonClicked = false;
}
//this always executes regardless of focusout or button click
var reply =confirm("Are you happy with the input?");
});
$('#btn').mousedown(function(event){
buttonClicked = true;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With