Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to automatically set the focus to a textbox when a web page loads using jQuery

by
Category:javascript
javascript jquery
How to automatically set the focus to a textbox when a web page loads using jQuery

This post will teach you how to automatically put cursor in form field using jQuery. So when you go to log into a website and the username field doesn’t automatically have the cursor in it when the page loads, you get a little frustrated.

HTML Code

<input type="text" id="username" name="username" />
<input type="text" id="password" name="password" />

jQuery Code

<script type="text/javascript">
    $('document').ready(function(){
        $("#username").focus();
    });
</script>

Complete page source here.

<!DOCTYPE html>
<html>
    <head>
        <title>Demo</title>
        <script src="http://bladephp.co/download/select2/jquery.min.js"></script>
    </head>
    <body>
        <input type="text" id="username" name="username" />
        <input type="text" id="password" name="password" />
    </body>
    <script type="text/javascript">
        $('document').ready(function(){
            $("#username").focus();
        });
    </script>
</html>

0 Comments


Html code work in comment box


Related Post