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.