LearnFast.Ninja

JavaScript select text in input

The main idea: Use the select function. Test the working example code.

The main idea: Use the select function. 
document.getElementById(InputID).select();
 
Working example code: 

<!DOCTYPE html>

<html>

<head>

    <title>Untitled Page</title>

    <script type="text/javascript">

        function Select_Text_In_Input(InputID) {

            document.getElementById(InputID).select();

        }

    </script>

</head>

<body>

    <input type="text" id="Input_4" onmouseover="Select_Text_In_Input(this.id);" value="SomeText" />

</body>

</html>
 
Result:


Tags

javascript

input select