javascript - Replace input text value by text in a string in REALTIME -
what need : when press key on keyboard in input text, replace content of string.
this have : https://jsfiddle.net/ypcxu27o/
<input id="edvalue" type="text" onkeyup="edvaluekey()"> function edvaluekey() { //var moninput = document.getelementbyid("edvalue").value; var montexte = 'this test'; var cpttexte = document.getelementbyid("edvalue").value; cpttexte = cpttexte.length; //alert(cpttexte); document.getelementbyid("edvalue").value = montexte.substr(0, cpttexte); //document.getelementbyid("edvalue").innerhtml = 'yuty'; }
my problem see key press before script replace it. is-it possible hide ?
thank you.
this should it:
document.getelementbyid('edvalue').addeventlistener('keydown', function(ev) { var montexte = 'this test'; if(ev.which !== 8) { //everything except backspace this.value= montexte.substr(0,this.value.length+1); ev.preventdefault(); } });
<input id="edvalue" type="text">
Comments
Post a Comment