javascript - Prompting a value with setTimeout function -


var label = prompt('label vertical line'); 

this code returns value in label enter in prompted field. want time delay prompted value.

i'm using code:

var label=alertwithoutnotice(); function alertwithoutnotice(){     var lab;     settimeout(function(){         lab=prompt('label vertical line');     }, 1200);     return lab; } 

but doesn't return value. please tell me wrong?

this chronological issue. settimeout schedules asynchronous event. means, until runs, rest of script continue execute.

the result return lab line executed before timeout callback fires. , on return, lab undefined @ point.

as such, can't return values asynchronous events, or @ least not meaningfully.

something jquery's deferred objects best route fix here, don't know if jquery option you.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -