jQuery

How to Get the Value in an Input Text Box using jQuery

In this tutorial, we are going to see how to get the value in an input text box using jQuery. You can simply use jQuery’s val() method to get the value of a text box.

Try the example below by entering any value in the text box and clicking the “Show value” button. The result is displayed in a dialog box.
 

How to Get the Value in an Input Text Box using jQuery
<!DOCTYPE html>
<html>
	<head>
		<title>Get the Value in an Input Text Box using jQuery</title>
		<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
		<script>
			$(document).ready(function(){
				$("#btn").click(function(){
					var str = $("#inpt").val();
					alert(str);
				});
			});
		</script>
	</head>
	<body>
		<input type="text" id="inpt">
		<button type="button" id="btn">Show value</button>
	</body>
</html>
Result
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *