Sometimes, we want to get text box value in JavaScript.
In this article, we’ll look at how to get text box value in JavaScript.
How to get text box value in JavaScript?
To get text box value in JavaScript, we can use the value property of the text box.
For instance, we write
<input type="text" name="txtJob" id="txtJob" />
to add an input element.
Then we write
const jobValue = document.getElementsByName("txtJob")[0].value;
to select the input boxes with name attribute txtJob with getElementsByName.
Then we use index 0 to get the first element.
And we get the value of the input with value.
Conclusion
To get text box value in JavaScript, we can use the value property of the text box.