Categories
JavaScript Answers

How to get text box value in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *