Categories
JavaScript Answers

How to get an input text value in JavaScript?

Spread the love

Sometimes, we want to get an input text value in JavaScript.

In this article, we’ll look at how to get an input text value in JavaScript.

How to get an input text value in JavaScript?

To get an input text value in JavaScript, we can use the value property.

For instance, we write

<input type="text" name="enter" class="enter" value="" id="input" />

to add an input.

Then we write

const value = document.getElementById("input").value;

to select the input with getElementById.

Then we get the input’s value with the value property.

Conclusion

To get an input text value in JavaScript, we can use the value property.

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 *