Click here to Skip to main content
15,880,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

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.

JavaScript
$.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.
 
Share this answer
 
v2
Check if it has the focus, that is what you're asking.

$(document.activeElement)

will apparently return the object that has focus.
 
Share this answer
 
Comments
aassaahh 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 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 16-Nov-12 22:50pm    
can i get some more info ,some example

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900