Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: User is typing

  1. #1
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts

    User is typing

    Wondering if I could get some help with this. Im trying to find a static way to see if someones typing, entered text etc...

    Currently, if you are typing, or enter anything in the input box it will say you are typing, and if u delete it, the message dissapears.. is there a way where if you're not typing at all it can say "You entered text" or something? maybe a way to time when the last key was pressed?

    Code:
    <script type="text/javascript">
    
        var Static = "You are typing.";
        
        function GetKeyUp(folder) {
            var temp = document.getElementById('textin').value;
            if (temp == 0) {
                document.getElementById('typing').innerHTML = "";
            }
            else {
                document.getElementById('typing').innerHTML = Static;
            }
            
        }
    
    </script>
    
    <input id="textin" type="text" name="box" onkeyup="GetKeyUp(this)" /> <input type="submit" value="Submit" name="submit" />
    <br /><br />
    <div id="typing" /></div>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,037
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Surely the user knows that he is typing / has typed something and does not need informing?

    Code:
    var Static = "You are typing.";
    var typed = "You have typed something";
    var tim;
       
    function GetKeyUp(folder) {
    window.clearTimeout(tim);
    var temp = document.getElementById('textin').value;
    if (temp == 0) {
    document.getElementById('typing').innerHTML = "";
    }
    else {
    document.getElementById('typing').innerHTML = Static;
    tim = setTimeout("haveTyped()", 2000);
    }
    }
    
    function haveTyped() {
    document.getElementById('typing').innerHTML = typed;
    }
    </script>
    
    <input id="textin" type="text" name="box" onkeyup="GetKeyUp(this)" /> <input type="submit" value="Submit" name="submit" />
    <br /><br />
    <div id="typing" /></div>


    <input id="textin" type="text" name="box" Why different element name and id?

    "Seize the day, put no trust in the morrow!" [Carpe diem, quam minimum credula postero.]
    Horace - Roman lyric poet & satirist (65 BC - 8 BC)
    Last edited by Philip M; 05-27-2009 at 10:49 AM.

  • #3
    Regular Coder
    Join Date
    Aug 2008
    Posts
    104
    Thanks
    4
    Thanked 14 Times in 14 Posts
    this may or may not work:

    Code:
    <input type = "text"  onblur="isNotTyping();" onkeyup = "isTyping();" value = "" />
    <p id = "response"></p>
    
    <script>
    var typing = false;
    
    function isTyping () {
    
    typing = true;
    document.getElementById("response").innerHTML = "You are typing";
    
    }
    
    function isNotTyping () {
    
    if(typing) {
       
       typing = false;
       document.getElementById("response").innerHTML = "";
    
    }
    
    }
    </script>

    of course you could modify it to timeOut if the user stops typing for couple of seconds...

    Code:
    <input type = "text"  onblur="isNotTyping();" onkeyup = "isTyping();" value = "" />
    <p id = "response"></p>
    
    <script>
    var typing = false;
    var timing = false;
    var timer;
    
    function isTyping () {
    
       typing = true;
       document.getElementById("response").innerHTML = "You are typing";
    
       if (timing) clearTimeout(timer);
       timer = setTimeout('isNotTyping();', 2000);
       timing = true;
    
    }
    
    function isNotTyping () {
    
    if(typing) {
       
       typing = false;
       timing = false;
       document.getElementById("response").innerHTML = "";
       
    }
    
    }
    </script>
    And to get rid of the message when the field is empty:

    Code:
    <input type = "text"  onblur="isNotTyping();" onkeyup = "if (this.value == '') isNotTyping(); else isTyping();" value = "" />
    <p id = "response"></p>
    
    <script>
    var typing = false;
    var timing = false;
    var timer;
    
    function isTyping () {
    
       typing = true;
       document.getElementById("response").innerHTML = "You are typing";
    
       if (timing) clearTimeout(timer);
       timer = setTimeout('isNotTyping();', 2000);
       timing = true;
    
    }
    
    function isNotTyping () {
    
    if(typing) {
       
       typing = false;
       if (timing) clearTimeout(timer);
       timing = false;
       document.getElementById("response").innerHTML = "";
       
    }
    
    }
    </script>
    Last edited by eddjc; 05-27-2009 at 10:11 AM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,037
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Sadly eddjc's script does not address the issue raised by the OP.

    "is there a way where if you're not typing at all it can say "You entered text" or something? maybe a way to time when the last key was pressed?"

  • #5
    Regular Coder
    Join Date
    Aug 2008
    Posts
    104
    Thanks
    4
    Thanked 14 Times in 14 Posts
    ach - it's mainly there. Anyone with half a brain can adapt the script I put up there to do that (hint: change the function setTimeout was leading to, and the else statement in "onKeyUp"). Anyway I was just trying to be helpful...

    in fact, what the hell:

    Code:
    <input type = "text"  id = "text_field" onblur="isNotTyping(this.value);" onkeyup = "if (this.value == '') isNotTyping(this.value); else isTyping();" value = "" />
    <p id = "response"></p>
    
    <script>
    var typing = false;
    var timing = false;
    var timer;
    
    function isTyping () {
    
       typing = true;
       document.getElementById("response").innerHTML = "You are typing";
    
       if (timing) clearTimeout(timer);
       timer = setTimeout('isNotTyping(document.getElementById('text_field').value);', 2000);
       timing = true;
    
    }
    
    function isNotTyping (string) {
    
      if(typing) {
       
         typing = false;
         if (timing) clearTimeout(timer);
         timing = false;
         if (string != '') document.getElementById("response").innerHTML = "You typed something";
         else document.getElementById("response").innerHTML = "";
       
      }
    
    }
    </script>
    better?

    Edd
    Last edited by eddjc; 05-27-2009 at 11:41 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •