Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
programmatically press keyboard key on button click event
Rupesh Kahane
Mar 24 2017 6:48 AM
345
Reply
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>
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
Source Error: [No relevant source lines] using kendo UI
why we need to copy constring from dll in to web project