|
|
how to make java script call synchronous
Hey !
i am doing field validation along with call back function in javascript. Call back function is setting a flag false.
At the end of validation i am submitting the form. Before submitting i am checking weather this flag is true or false.
The problem is form.submit() executes before the response of call back function.
But if i put alert(); between call back function and form.submit(), it work's fine.
i have tried putting setTimeout(quot;quot;,5000) but does not work for me.
This is my call back functionCode:function validRange(){ var flag = true; var low = document.getElementById(quot;lowRangequot;); var high = document.getElementById(quot;highRangequot;); accountsService.isValidRange(low.value, high.value,{callback: function(flags){ if(!flags){ flag = false;}}}); return flag;
}
here is a function for submitting formCode:
function validateAccountForm(num){ var flag = true; if(validRange()){if(window.confirm(quot;Do You want to Continue Account Settings?quot;)) document.getElementById(quot;accountFormquot;).submit();else flag = false; } else { flag = false; }
return flag;
}
Let's assume we are having invalid range of code so, in above method validRange() should return false, but response from call back function is real slow and validRange() method simply returns the default value for flag i-e true.
I want my call back function to process completely and than go for submitting a form.
Any one got any suggestions?
Regards !
Wjaahat
Your question has nothing to do with Spring. It should belong to a javascript or Ajax forum.
Oh yeah, there is not much information available what ajax, javasript or whatever framework you are using, always helpful.
I suppose DWR.
The sollution is, use dwr.engine.async(true) or equal function. Read the documentation of it at the site of dwr.
thanks Asshen-Sukar, let me go for that documentation
yeah it is DWR.
One last thing, how can i delete this thread from here ? |
|