JavaScript

How to get the value from the input field in Javascript

You can simply use the value property of the input element to get the value. The following example displays the text entered in the input when you click the “Get value” button.
 

HTML Code:
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Get the value from the input field</title>
	</head>
	<body>
		<input type="text" placeholder="Enter a value here..." id="in">
		<button type="button" onclick="getValue();">Get the value</button>
		
		<script>
			// Put the javascript code here.
		</script>
	</body>
</html>

 

 

Javascript Code:
function getValue() {
    // Select the input element and get its value
    var input = document.getElementById("in").value;

    // Display input value
    alert(input);
}
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 *