Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript jQuery
Hi, I have a asp.net texbox as
 <asp:TextBox ID="TextBox2" onblur="myfunction()"  runat="server"></asp:TextBox>
and a button
<input type="button" id="Button1" onclick="dosomething()" value="Click Me!ajax" />
 
function myfunction(){
alert("textbox onblur");
}     
function dosomething(){
alert("button onclick");
}                                              
 
Whenever I write something on the texbox and press tab or click anywhere in the form
alert("textbox onblur");
is executed ,But the problem is ,if i dont press tab or click on the form and directly try to press the button
onblur method is not executed ,first the button onclick event is executed and at last the onblur is executed ,plz help.I want the onblur should be executed first.
Posted 16-Nov-12 5:42am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check if it has the focus, that is what you're asking.
 
$(document.activeElement)
 
will apparently return the object that has focus.
  Permalink  
Comments
aassaahh at 16-Nov-12 12:01pm
   
yes,i have already tryied this in the button onclick
function ie
function dosomething(){
alert("button onclick");
}
but i am getting active element as the button not the textbox.
Christian Graus at 16-Nov-12 12:02pm
   
Of course. You clicked the button. It is now active. Is there a cursor visible in the text box ? There shouldn't be. You would have to track which textbox was last selected to do what you want.
aassaahh at 16-Nov-12 22:50pm
   
can i get some more info ,some example
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

as per i can see, you are using ajax call. ajax is server side code.which takes time, in mean while client side code get executed. you have to synchronizes it. using asynckeyword in ajax call.
eg.
 
$.ajax({
async: false,
url: url,
data:{ posNo :$(this).parents('tr').find('input[id*="ordPosno"]').val(), tranDate :$('input[id*="orSalesdate"]').val()},
success:function(flag){
if(flag.length > 0){
posFlagvalue=flag;
}
}
});
 
you have to show some waiting kind popup.while execution of ajax.
}
if you are not using it. its working fine in my simple program check it.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 468
1 Sergey Alexandrovich Kryukov 305
2 PhilLenoir 115
3 RajeeshMenoth 110
4 Uma Shankar Patel 80
0 Sergey Alexandrovich Kryukov 6,557
1 OriginalGriff 5,966
2 CPallini 2,473
3 Richard MacCutchan 1,687
4 Abhinav S 1,540


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100