Get the Value of Text Input Field using JavaScript Last Updated : 09 Jan, 2025 Comments Improve Suggest changes Like Article Like Report Getting the value of a text input field using JavaScript refers to accessing the current content entered by a user in an input element, such as <input> or <textarea>, by utilizing the value property. This allows for dynamic interaction and data manipulation in web forms.Syntax inputField.value;inputField.value = text;Getting the Value of a Text Input FieldThe value property in JavaScript represents the current value of an input element, such as <input>, <textarea>, or <select>. It allows you to access and manipulate the text, number, or selected option within the input element.Example: Here, we are using the Value property to get the value of the text input field.An <input> element with the ID "myInput" is defined.A button with an onclick event handler is provided to trigger the getValue() function.The getValue() function retrieves the input element using getElementById(), accesses its value property to get the text entered by the user, and displays it in an alert. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Using Value Property</title> </head> <body> <!-- Input field --> <input type="text" id="myInput" placeholder="Enter text"> <!-- Button to get input value --> <button onclick="getValue()">Get Value</button> <!-- Script to get input value --> <script> function getValue() { // Get the input element by its ID let inputField = document.getElementById("myInput"); // Get the value of the input field let value = inputField.value; // Display the value in an alert alert("Input value: " + value); } </script> </body> </html> Output:Getting the Value of a TextareaExample : Here, we are getting the text area value using value property.A <textarea> element with the ID "myTextarea" is defined.A button with an onclick event handler is provided to trigger the getValue() function.The getValue() function retrieves the <textarea> element using getElementById(), accesses its value property to get the text entered by the user, and displays it in an alert. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Textarea Value Example</title> </head> <body> <!-- Textarea --> <textarea id="myTextarea" rows="4" cols="50" placeholder="Enter text"></textarea> <!-- Button to get textarea value --> <button onclick="getValue()">Get Value</button> <!-- Script to get textarea value --> <script> function getValue() { // Get the textarea element by its ID let textarea = document.getElementById("myTextarea"); // Get the value of the textarea let value = textarea.value; // Display the value in an alert alert("Textarea value: " + value); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article Get the Value of Text Input Field using JavaScript A ashishsaini3 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads Set the Value of an Input Field in JavaScript We will learn how you can set the value of an input field in JavaScript. We will set user input to the placeholder value of the input field using JavaScript.Below are the approaches to set the value of an input field in JavaScript:Table of ContentBy using the innerHTML propertyBy using setAttribute 2 min read How to Get the Value of an Input Text Box using jQuery? When working with forms or interactive web pages, sometimes need to get the values entered into the input fields. This article provide a complete guide on how to get the value o an input text box using jQuery. Below are the different approaches to get the value of an input text box using jQuery:Get 2 min read JQuery Set the Value of an Input Text Field Set the value of an input text field in jQuery is useful while working with forms. It is used to add new value to the input text field. In jQuery, there are various methods to set the value of input text fields, these are - val(), prop(), and attr(). These method offers unique capabilities for setti 3 min read How to Get Selected Value in Dropdown List using JavaScript? A dropdown list is an HTML element that allows users to select one option from a list of options. The <select> and <option> tags are used to create dropdown lists in HTML. In this article, we will see how to get selected value from dropdown list using JavaScript.Basic HTML Structure for 2 min read How to get Values from HTML Input Array using JavaScript? This problem can be solved by using input tags having the same "name" attribute value that can group multiple values stored under one name which could later be accessed by using that name. Syntaxlet input = document.getElementsByName('array[]');What is an Input Array in HTML?An "input array" in HTML 2 min read How to force Input field to enter numbers only using JavaScript ? We are going to learn how can we force the Input field to enter numbers only using JavaScript. Below are the approaches to force input field force numbers using JavaScript:Table of ContentBy using ASCII ValueBy using replace(), isNan() functionBy using ASCII ValueIn this approach, we are going to us 3 min read How to take user input in JavaScript? Interacting with users is the best way to create engaging and dynamic web applications. Taking user input allows your applications to be interactive and responsive. Here we will see the approach to take user input in JavaScript, specifically using the prompt method, which is perfect for beginners.Ap 3 min read How to get the value of a textarea in jQuery ? To get the value of a textarea in jQuery, you can use the val() method. This method is commonly used to retrieve the current value of form elements like textarea, input, and select. It works by either retrieving or setting the value of the selected element. If no input is provided, the method return 2 min read How to get hidden field array values in javascript? To retrieve values from hidden fields in JavaScript, you can use methods like querySelectorAll or getElementsByName to select these elements and extract their values. This can be useful for gathering data that isn't directly visible on a web page but still needs to be accessed or processed.Example U 2 min read How to make a Value/Text Input using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a Value/Text Input using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=âstylesheetâ h 1 min read Like