0

How do I simulate a keypress into a input tag without jQuery? I looked at Simulate keypress without jquery but it didn't seem to help. Example of what I'm trying to do:

<inputobject>.simulatekeypress('a');

Please do not submit any jquery answers.

1 Answers1

-1

function simulatekeypress(char) { 
  document.getElementById("input").value += char;
}

// simulatekeypress("a");
Input: <input id="input" value="123" />
<p>
  <button onclick="simulatekeypress('a');">
    Simulate key press
  </button>
</p>
Old Geezer
  • 14,854
  • 31
  • 111
  • 198