sleep func

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
motiksir
Forum Newbie
Posts: 15
Joined: Sat Oct 22, 2011 5:33 pm

sleep func

Post by motiksir »

[*]
hi 
i try to do a virtual chat..
and i want to do a sleep func before that i accept answer..
for example:
you:hi
(sleep 3 sec)//there is a label that write "virtual chat typing"
virtual chat:hi my friend
how i can do sleep func in javascript...
I try to do SetTimeout.. but when appear the status message, the message of virtual chat appear without wait..
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: sleep func

Post by twinedev »

If you are trying to use the SetTimeout() in javascript like you use sleep() in PHP, that is where the problem is.

Check out this page for explanation and examples of how it works:

http://www.w3schools.com/js/js_timing.asp

-Greg
motiksir
Forum Newbie
Posts: 15
Joined: Sat Oct 22, 2011 5:33 pm

Re: sleep func

Post by motiksir »

function ContactingOn(){
$("#statusLabel").html("<div id='typing'>adi type..</div>");
setTimeout("$("#statusLabel").html("");", 3000); //delete "adi type..."after 3 second

//i need that to be a sleep of 3 sec

addLineAgent("mkasdmlasdmasdkl"); //func that add string to frame


$("#statusLabel").html("<div id='typing'>adi type..</div>");
setTimeout("$("#statusLabel").html("");", 3000); //delete "adi type..."after 3 second

//i need that to be a sleep of 3 sec

addLineAgent("mkasdmlasdmasdsasdasddsasaddsadsasdkl");
}


the problem his that it continue in the program without wait 3 sec..
Post Reply