How to change input text to upper case with JavaScript?

Estimated read time 1 min read

You can change the text of an input element to uppercase using JavaScript by accessing the value property of the input element and using the toUpperCase() method. Here’s an example:

<input type="text" id="inputText">

<script>
  var input = document.getElementById("inputText");
  input.addEventListener("input", function() {
    this.value = this.value.toUpperCase();
  });
</script>

In this example, we first get a reference to the input element by using document.getElementById("inputText"). Then, we add a input event listener to the input that triggers whenever the value of the input changes.

The event listener sets the value of the input to its uppercase equivalent using the toUpperCase() method. This way, every time a user types something into the input, it will automatically be converted to uppercase.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply