-3

i am making an interviewing chatbot using programO (i am new to php) in which i want to display a message if for long time there is no activity on chat window. i hav searched jquery plugins but they are for detecting mouse or keyboard strokes but i am just concerend with detecting that whether the chat window is upadted with a user input or not . i hav also searched javascript settimeout and settimeinterval functions to display a message but i am unable to understand how to use them with chat window form.

  • if you want to get just the response of in chat window, then just use `setInterval('', 1000)` in one minute, and get the data from where you store the chat data. for more info about see the related question http://stackoverflow.com/questions/10613268/not-able-to-handling-ajax-request-from-a-small-chat-module/10613343#10613343 – jogesh_pi May 24 '12 at 07:14
  • i have been trying to use setTimeout function. function timeout_trigger() { alert("say something"); } if(!isset($_POST['SAY'])) { setTimeout('timeout_trigger()', 3000); } say is my button on chat form for submitting input. – Jawaria Irfan May 24 '12 at 16:59

1 Answers1

0

setTimeout needs to be used in conjunction with clearTimeout. Use clearTimeout whenever a time resetting event occurs.

Example:

<script>
    var interval = -1;
    var TIMEOUT = 5; // seconds
    function doTimeout(){
        alert('show timeout message');
        startClock(); // if you want to restart the timer
    }
    function startClock(event){
        console.log("foo",interval, event);
        if(interval !== -1){
            console.log("clearing timeout");
            clearTimeout(interval);
        }
        interval = setTimeout(doTimeout,TIMEOUT*1000);
    }
    startClock(); // if you want to start the timer on arrival
</script>

<!-- add remove events as you see fit -->
<textarea id="chatinput" onblur="startClock(event)" onfocus="startClock(event)" onchange="startClock(event)" onkeyup="startClock(event)"></textarea>

For more on timeout:
tags:
questions: javascript setTimeout clearTimeout

Community
  • 1
  • 1
Shanimal
  • 11,517
  • 7
  • 63
  • 76