Trigger button click on enter key JavaScript

Trigger button click on enter key JavaScript

Today, We want to share with you .
In this post we will show you javascript trigger enter key, hear for How To Trigger Button Click on Enter we will give you demo and example for implement.
In this post, we will learn about Trigger button click on enter key JavaScript with an example.

Trigger a button click with JavaScript on the Enter key in a text box

In this post, we will learn about how to Trigger a button click with JavaScript on the Enter key in a text box with an example.

Now in this post, I will explain how to Trigger a button click with JavaScript on the Enter key in a text box with appropriate example.

READ :  Angularjs get last item Array Object and json Example

Many a times you may require to fire a button click event when user press enter key in textbox , you can achieve this with the help of JavaScript or Jquery.

Now create  Web form application in Visual Studio and write below lines of code in it.

1 . Using Jquery resolve Error.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        $("#txtName").keyup(function (event) {
            if (event.keyCode === 13) {
                $("#btnSave").click();
            }
        });
    </script>
</head>
<body>
    <input type="text" id="txtName"/>
    <input type="button" id="btnSave" value="btnSave" onclick="doSomeCode();" />
</body>
</html>

 2. Using Javascript with AngularJS

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        document.getElementById("txtName").addEventListener("keyup", function (event) {
        event.preventDefault();
        if (event.keyCode === 13) {
            document.getElementById("btnSave").click();
        }
    });
    </script>
</head>
<body>
    <input type="text" id="txtName" />
    <input type="button" id="btnSave" value="btnSave" onclick="doSomeCode();" />
</body>
</html>

Read :

READ :  AngularJS SEO - Single Page App Crawling and Indexing

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Trigger button click on enter key jquery.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Add a Comment

Your email address will not be published. Required fields are marked *