Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
How to get value of textbox in jQuery ?
Next article icon

How to Get the Value of an Input Text Box using jQuery?

Last Updated : 08 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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 the Value of an Input Text Box using val() Method

jQuery val() method is used to get the value of an input text box. This function is used to set or return the value. To get the value of an input text box, you can simply call this method on the element.

Syntax

$('selector').val()

Example: This example explains the steps to get the value of an input text box using jQuery.

html
<!DOCTYPE html> <html lang="en">  <head>     <script src= "https://code.jquery.com/jquery-3.4.1.min.js">     </script>      <script>         $(document).ready(function () {              // On button click, get value              // of input control              $("#getValBtnID").click(function () {                 const inputString = $("#userInputID").val();                 alert(inputString);             });         });      </script> </head>  <body style="text-align: center">     <h3 style="color:green">         GeeksForGeeks     </h3>      <b>JQuery val() Method</b>      <br><br>      <input type="text" id="userInputID">     <br><br>      <button type="button" id="getValBtnID">         Get Value     </button> </body>  </html> 

Output:

propGetter

Get the Value of an Input Text Box using prop() Method

The prop() method can also be used to get the entered value of text box. Pass the property name as a parameter of prop() method and get the value of the passed property. In case of input text box, we will pass the value property as parameter to the prop() method.

Syntax

$('selector').prop('value');

Example: The below example will explain the use of the prop() method to get the value of the input text box.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <script src= "https://code.jquery.com/jquery-3.4.1.min.js">     </script>      <script>         $(document).ready(function () {             // On button click, get value              // of input control              $("#getValBtnID").click(function () {                 const inputString = $("#userInputID").prop('value');                 alert(inputString);             });         });      </script> </head>  <body style="text-align: center;">     <h3 style="color:green">         GeeksForGeeks     </h3>      <b>JQuery val() Method</b>      <br><br>      <input type="text" value="" id="userInputID">     <br><br>      <button type="button" id="getValBtnID">         Get Value     </button> </body>  </html> 

Output:

propGetter

jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous for its philosophy of “Write less, do more”. You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples.



Next Article
How to get value of textbox in jQuery ?

M

mohitgouti
Improve
Article Tags :
  • JQuery
  • Web Technologies
  • jQuery-Questions

Similar Reads

  • 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 create a Textarea Input Box 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 a Textarea Input box using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=”stylesheet” href=”ht
    1 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
  • How to get value of textbox in jQuery ?
    The purpose of this article is to demonstrate how we can get the value of textbox using jQuery. A basic understanding of HTML, CSS, and jQuery is required. This can be done by using the jQuery val() method. val() Method: This method is used to set or return the value of the attribute for the selecte
    2 min read
  • How to create a 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 a Text Input using jQuery Mobile. Approach: First, we add the jQuery Mobile scripts needed for the project. <link rel=”stylesheet” hre
    1 min read
  • How to get the outer html of an element using jQuery ?
    Sometimes, there is a need to get the entire HTML element by its id and not merely its contents, for doing so, we shall use the HTML DOM outerHTML Property to get the outer HTML of HTML element. Syntax: document.getElementById("your-element-id").outerHTML) You can use a variable and initialize it to
    2 min read
  • How to change the checkbox value using jQuery ?
    The Checkboxes are used to let a user select one or more options for a limited number of choices. The :checkbox selector selects input elements with type checkbox.Syntax: $('#textboxID').val($("#checkboxID").is(':checked')); In the above syntax, basically the return value of the checked or unchecked
    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 text value of a selected option in jQuery ?
    Introduction: In this article, we will see how we can use jQuery to get the text value from the selected option. While working on some form-related user interface, we often use the select option, and to use that, we will surely need those values that are being selected. Approach: We will use select
    2 min read
  • How to specify the value of an input element using HTML ?
    In this article, we will set the value of an input element using HTML. The value attribute for <input> element in HTML is used to specify the initial value of the input element. It has different meaning for different input type: The “button”, “reset” and “submit” property specifies the text on
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences