I have a problem with this script, I want to replace anything entered in the input field with a specific letter in real time, with Hello World in the field.
<input id="inputID" type="text" value="" maxlength="11"/>
$('#inputID').keyup(function(e){
var cv=["h","e","l","l","o"," ","w","o","r","l","d",""];
var i=$('#inputID').val();
for (j=0;j<11;j++){
this.value = this.value.replace(i[j],cv[j]);
}
});
This script works well when I write slowly but not when I write quickly. thanks for your help
Try this way:
$('#inputID').keyup(function(e){
var cv = 'hello world';
this.value = cv.substr(0, this.value.length);
});
See the working demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With