Hello everyone i just picked up jQuery
So my question is i want to stop a key from repeating when you hold it down
Example: Edit (i want it to stop .. so 1 character per keypress/keydown)
keypress: a
HoldDown: aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
My code is:
<input type='text'>
var stop= false;
var time =null;
$(':text').keypress(function(e) {
if(stop === true){e.preventDefault();}
if (time !== null) {
lastkey = time;
}
time = new Date().getTime();
var between = time - lastkey;
if (between <= 70) {
stop = true;
}
});
$(':text').keyup(function(){stop = false;});
Am i going about this the wrong way?
Use the
.keyup()
bind instead of.keypress()
.Try this: http://jsfiddle.net/maniator/yFA8c/
It will only allow a letter per every 2 seconds.
Code:
You should use keydown and keyup events instead keypress.
So, here is a solution: