Click here to Skip to main content
12,999,608 members (116,414 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, I have a 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
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.

async: false,
url: url,
data:{ posNo :$(this).parents('tr').find('input[id*="ordPosno"]').val(), tranDate :$('input[id*="orSalesdate"]').val()},
if(flag.length > 0){

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Check if it has the focus, that is what you're asking.


will apparently return the object that has focus.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2017
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