Jump to content

Jquery Trigger An Event When User Has Stopped Writing


s4surbhi2218

Recommended Posts

Hi ,

I am making a program in which text goes when user types similar to facebook status update textbox the grey text goes away when user types

 

i have used

[code
]<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$("documnet").ready(
function(){
$(document).keypress(function(event) {
if (event.keyCode != 1 && event.keyCode != 2 && event.keyCode != 3)
{
$('input[type=text]').val('');
// alert('this is not mouse!');
}
});
</script>
</head>
<body>
<input type="text" id="txt" value="Surbhi">
</body>
</html>
[/code]

 

but the problem is user is only able to type one alphabet in this.

Any suggestions ???

Thanks

Link to comment
Share on other sites

Here's one way to do it off the top of my head. I set it to 750 milliseconds after you're done typing.

Demo: http://xaotique.no-ip.org/tmp/32/

 

HTML

<input type="text" id="type" />
<span id="status"></span>

 

Javascript / jQuery

// Allow page to load.
$(document).ready(function()
{
   // Set our timer global and give a timeout for stop typing.
   var timer, timeout = 750;

   // Just clearing anything the user has in the text field on load.
   $("#type").val("");

   // Watch for the user to type in the text field.
   $("#type").keyup(function()
   {
       // Clear timer if it's set.
       if (typeof timer != undefined)
           clearTimeout(timer);

       // Set status to show we're typing.
       $("#status").html("Typing ...").css("color", "#009900");

       // Set status to show we're done typing on a delay.
       timer = setTimeout(function()
       {
           $("#status").html("Stopped").css("color", "#990000");
       }, timeout);
   });
});

Link to comment
Share on other sites

Here's one way to do it off the top of my head. I set it to 750 milliseconds after you're done typing.

Demo: http://xaotique.no-ip.org/tmp/32/

 

HTML

<input type="text" id="type" />
<span id="status"></span>

 

Javascript / jQuery

// Allow page to load.
$(document).ready(function()
{
// Set our timer global and give a timeout for stop typing.
var timer, timeout = 750;

// Just clearing anything the user has in the text field on load.
$("#type").val("");

// Watch for the user to type in the text field.
$("#type").keyup(function()
{
// Clear timer if it's set.
if (typeof timer != undefined)
clearTimeout(timer);

// Set status to show we're typing.
$("#status").html("Typing ...").css("color", "#009900");

// Set status to show we're done typing on a delay.
timer = setTimeout(function()
{
$("#status").html("Stopped").css("color", "#990000");
}, timeout);
});
});

 

Its pretty!!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.