
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Is it possible to select text boxes with JavaScript?
Yes, select text box with JavaScript using the select() method. At first, let us create an input text −
Enter your Name:<input type="text" id="txtName" value="John"> <br> <button type="button" onclick="check()">Select Text Box</button>
Now, let us select the text box on button click −
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> Enter your Name:<input type="text" id="txtName" value="John"> <br> <button type="button" onclick="check()">Select Text Box</button> <script> function check(){ document.getElementById("txtName").select(); } </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 click the button “Select Text Box”, it will select the text box. This will produce the following output −
- Related Articles
- How to create custom select boxes with CSS and JavaScript?
- Align text and select boxes to the same width with HTML and CSS
- Queries to check if it is possible to join boxes in a circle in C++
- How to Copy Chart with Text Boxes in Excel?
- Queries to check if it is possible to join boxes in a circles in C++ Program
- Insert the results of a MySQL select? Is it possible?
- Can we select row by DATEPART() in MySQL? Is it possible?
- Is it possible to change the HTML content in JavaScript?
- Is it possible to have a HTML SELECT/OPTION value as NULL using PHP?
- Is it possible to write to MongoDB console in JavaScript execution?
- Is it possible to write data to file using only JavaScript?
- JavaScript code to de-select text on HTML page.
- Is it possible to display substring from object entries in JavaScript?
- Is it possible to create a new data type in JavaScript?
- Is it possible to have JavaScript split() start at index 1?

Advertisements