solvit.io

Set the focus on an input text automatically when the web page loads

This selects the element automatically so visitors can type in it without having to click on it first.

HTML 5
<!-- ... -->
<body>
    <!-- ... -->
    <input type="text" name="..." id="..." autofocus>
</body>
JavaScript
<head>
    <!-- ... -->
    <script>
        window.onload = function() {
            document.getElementById('the-input').focus();
        }
    </script>
</head>
<body>
    <!-- ... -->
    <input type="text" name="..." id="the-input">
</body>
Find more solutions about: , , ,