Tuesday 5 December 2017

javascript - JS : How to use return type of callback function for returning the main callee function

itemprop="text">

I found few good links ( href="https://stackoverflow.com/questions/6847697/how-to-return-value-from-an-asynchronous-callback-function">How
to return value from an asynchronous callback function? and href="https://stackoverflow.com/questions/23339907/returning-a-value-from-callback-function-in-node-js">Returning
a value from callback function in Node.js etc) of SO but they are not not able
to provide solution to my problem.



My Problem: able
to get result of asynchronous call, but how I can use this result for returning of my
function?



onsubmit = "return
checkForm(function(callBackResponse) { alert(callBackResponse)
});"


Here getting
value of callBackResponse either as true or false, and want to use this value as :




onsubmit = "return
responseFromCallBack;"


EDITED
: Here is my async stuff



function checkForm(callback)
{return firstCallBack(function secondCallBack(response) {
if (some
conditions) {
response = false;

callback(response);

}
else {
response =
true;
callback(response);
}
}

);
}

class="post-text" itemprop="text">
class="normal">Answer





If i get ur issue correctly: />you want to "validate" (checkForm()) before submitting?!
in this case
set an event listener to the form submit-event...
prevent
(event.preventDefault()) the default behavior (submit) call
your function (checkForm()) if everything is fine, trigger the submit manually ;) />e.g. document.getElementById('myFormId').submit()



Cheerio :)



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...