How do I get the value of text input field
- 0
Hi,
How do I get the value of an input field using Javascript?
Thanks
Answers
- 1
To get the value of an input field in JavaScript, you can use the value property of the HTMLInputElement object.
Here is an example:
<input type="text" id="myInput">
<script>
// Get the input element
var input = document.getElementById("myInput");
// Get the value of the input element
var inputValue = input.value;
console.log(inputValue);
</script>
You can also use the value property to set the value of the input field:
<input type="text" id="myInput">
<script>
// Get the input element
var input = document.getElementById("myInput");
// Set the value of the input element
input.value = "Hello, World!";
</script>