I have one textbox & button. On button click event I have too show some keyboard value (example I have to show number 2 into a textbox)
How can I do a javascript code which will automatically press a key & show a text into a textbox.
I tried with below code. Suggest me something.
Thanks in advance.
- <input type="text" id="myInputTextBoxId" value="">
- <button id="myButton" type="button">Generate Text</button>
-
- <script>
- document.getElementById("myButton").addEventListener("click", function() {
- var press = jQuery.Event("keypress");
- press.which = 50;
- $('#myInputTextBoxId').trigger(press);
- $('#myInputTextBoxId').focus();
- });
- </script>