
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Submit textbox on pressing ENTER?
The ENTER has the key code 13. We will use the event.keycode to check whether ENTER is pressed or not. Following is the code −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initialscale=1.0"> <title>Document</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <input type="text" id="name"/> <script> document.getElementById("name").addEventListener("keydown", function(event) { if (!event) { var event = window.event; } event.preventDefault(); if (event.keyCode == 13){ login(); } }, false); function login(){ console.log("submitted successfully...."); } </script> </body> </html>
To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.
Output
This will produce the following output −
When you press ENTER key, the following message would be visible on console as in the below screenshot −
- Related Questions & Answers
- What is the jQuery Event for user pressing enter in a textbox?
- How to detect pressing Enter on keyboard using jQuery?
- How to trigger click event on pressing enter key using jQuery?
- Lose input hints (get focus) after pressing mouse cursor in a textbox with JavaScript
- JavaScript Trigger a button on ENTER key
- How to fire after pressing ENTER in text input with HTML?
- How to simulate pressing enter in html text input with Selenium?
- Call the same function when clicking a Button and pressing Enter in Tkinter
- How to call a JavaScript function on submit form?
- Change value of input on form submit in JavaScript?
- How to output JavaScript into a Textbox?
- Enter key press event in JavaScript?
- How to trigger a button click on keyboard "enter" with JavaScript?
- Enter values with prompt and evaluate on the basis of conditions in JavaScript?
- How to display value of textbox in JavaScript?
Advertisements