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
Post a Comment