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

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);
   });
});

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!!!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.