how to get input value in jquery?

Today, We want to share with you how to get input value in jquery?.In this post we will show you how to get all textbox value in jquery?, hear for get textbox value in jquery on button click we will give you demo and example for implement.In this post, we will learn about Get Selected Radio Button value using jQuery with an example.

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

Example 1: Get the value in an input text box

//Get
var bla = $('#product_name').val();

//Set
$('#product_name').val(bla);

First way to get a value

value = $("#product_name").val(); 

Second way to get a value

value = $("#product_name").attr('value');

JavaScript to get the value

document.getElementById('product_name').value 

Use the jQuery val() Method

index.html

<!DOCTYPE html> 
<html lang="en"> 

<head> 
	<script src= 
"https://code.jquery.com/jquery-3.4.1.min.js"> 
	</script> 

	<script> 
		$(document).ready(function () { 

			$("#getValBtnID").click(function () { 
				var inputString = $("#productDataGetID").val(); 
				alert(inputString); 
			}); 
		}); 
	</script> 
</head> 

<body> 
	<h3 style="color:green"> 
		Www.pakainfo.com 
	</h3> 

	<b>JQuery val() Method</b> 
	
	<br><br> 
	
	<input type="text" id="productDataGetID"> 
	<br><br> 

	<button type="button" id="getValBtnID"> 
		Get Value 
	</button> 
</body> 

</html> 

Example onther: index.html

<!DOCTYPE html> 
<html> 

<head> 
	<script src= 
"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> 
	</script> 

	<script> 
		$(document).ready(function () { 
			$("#setBtnID").click(function () { 
				$("input:text").val("Welcome To Pakainfo!"); 
			}); 
		}); 
	</script> 
</head> 

<body> 
	<h2 style="color:red"> 
		Www.pakainfo.com  
	</h2> 
	
	<b>JQuery val() Method</b> 

	<p>User Text: <input type="text"
		name="productDataGet"> 
	</p> 

	<button id="setBtnID"> 
		Set the value of the 
		input field 
	</button> 
</body> 

</html> 

I hope you get an idea about get input value javascript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.