-2

I have a input box where something is already written, where i want to focus and trigger some fake keypress A, B and C one by one as if someone is typing in that textbox i just don't want to change the innerHTML of the textbox but i want to achieve a typing effect Please provide a solution using JS Thanks in advance

  • Provide a code. – moon Dec 02 '17 at 08:02
  • 1
    Welcome to Stackoverflow, please read [How To Ask](https://stackoverflow.com/help/how-to-ask). Pay special attention to [How To Create MCVE](https://stackoverflow.com/help/mcve). The more effort you'll put into posting a good question: one which is easy to read, understand and which is [on topic](https://stackoverflow.com/help/on-topic) - the chances are higher that it will attract the relevant people and you'll get help even faster. Good luck! – Nir Alfasi Dec 02 '17 at 08:08
  • Possible duplicate of [Is it possible to simulate key press events programmatically?](https://stackoverflow.com/questions/596481/is-it-possible-to-simulate-key-press-events-programmatically) – JJJ Dec 02 '17 at 08:37

1 Answers1

0

var a = document.getElementsByTagName('input')[0];
var i = 0;
var plc = 'type A B C';
var speed = 300;

a.addEventListener('focus',triGr)

function triGr(){
if(i < plc.length){
a.placeholder += plc.charAt(i);
i++;
setTimeout(triGr, speed);
}
}
<input id="name" name="name" type="text"  placeholder="" required>
vicky patel
  • 699
  • 2
  • 8
  • 14