Want to get the Value in an Input Text Box using jQuery? Use the jQuery val() Method. Following is an example to get the Value in an Input Text Box.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Get the Value of an Input Text Box</title> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <script> $(document).ready(function(){ // Get value on button click and show alert $("#myBtn").click(function(){ var str = $("#myInput").val(); alert(str); }); }); </script> </head> <body> <input type="text" id="myInput"> <button type="button" id="myBtn">Show Value</button> </body> </html> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.