How to select the value of input onClick

October 13, 2022 No comments javascript random input select

Introduction

In JavaScript, we may need to select the value of input after clicking the field. We'll examine how to do it in this tutorial.

How to select the value of input onClick

To select the value of input after clicking inside the field we can simply use the select() function:

In HTML:

<input type="text" onclick="select()"/>

Programmatically in JavaScript:

document.getElementById("inputField").onclick = function() {
    this.select();
};

Conclusion

In this article, we learned how to select the value of input onClick.

{{ message }}

{{ 'Comments are closed.' | trans }}