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>
		<meta charset="utf-8">
		<title>Get the value from the input field</title>
		<input type="text" placeholder="Enter a value here..." id="in">
		<button type="button" onclick="getValue();">Get the value</button>
			// Put the javascript code here.



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

    // Display input value
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 *