---
title: "Focusing a Textbox using Jquery"  
description: "In this blog, I’m explaining how to set focus on textbox on page load using jquery.  Suppose you have login form in your project and you want to set t"  
author: "Sumit Kesarwani"  
published: 2014-03-15  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/657/focusing-a-textbox-using-jquery  
category: "jquery"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# Focusing a Textbox using Jquery

In this blog, I’m explaining how to set focus on textbox on [page load](https://www.mindstick.com/articles/12909/how-to-open-first-time-popup-on-page-load-in-website) using jquery.\

Suppose you have [login form](https://www.mindstick.com/articles/12852/styles-login-form-in-android) in [your project](https://www.mindstick.com/forum/156583/best-way-to-link-bootstrap-file-in-your-project) and you want to set the focus on the [username](https://www.mindstick.com/forum/12798/there-is-no-viewdata-item-of-type-ienumerable-selectlistitem-that-has-the-key-username) textbox when your login form page loads, this can be achieved by following the below simple steps:

Step 1:

Create a n empty [asp.net application](https://www.mindstick.com/forum/540/using-stored-procedures-with-entity-framework-in-an-asp-dot-net-application) and add a webform to it.

Step 2:

Now [add two](https://www.mindstick.com/forum/156862/write-a-c-sharp-program-to-add-two-numbers-without-using-operator) textbox one for username and one for [password](https://www.mindstick.com/blog/118/retriving-user-password-by-using-stored-procedure-in-asp-dot-net) like this:

\
![Focusing a Textbox using Jquery](https://www.mindstick.com/blogs/b7fd7f5f-a0a1-4849-a0e9-a1b89f82ed16/images/a0013e23-feb2-43a4-8664-dcebb19eeb1e.png)

Now you want set the focus on the username textbox so that the user can directly write in it. For this you have to download the jquery-1.11.0.min.js file and add it your project.

##### Step 3:

Now once you have add the jquery-1.11.0.min.js file to your project, you have access to jquery methods and properties and you will be able to write jquery code.

Add <script src="jquery-1.11.0.min.js"></script> in the head section of the webfrom by drag and drop from the solution explorer.

##### Step 4:

Add the below code in the head section of the form :-

```
<script type="text/javascript">        $(document).ready(function () { //ready method calls before the page loads            $('#username').focus(); //username is the id of the textbox and focus method set the focus on the textbox.        });    </script>
```

##### Output

![Focusing a Textbox using Jquery](https://www.mindstick.com/blogs/b7fd7f5f-a0a1-4849-a0e9-a1b89f82ed16/images/55744590-a8f9-41a1-9209-03e7859edcd3.png)

Now you can see the username textbox has focus as soon as the page loads.

Full Code

```
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Focus.aspx.cs" Inherits="JQueryApp2.WebForm1" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>    <script src="jquery-1.11.0.min.js"></script>    <script type="text/javascript">        $(document).ready(function () {            $('#username').focus();        });    </script></head><body>    <form id="form1" runat="server">        <div>            Username :            <input type="text" id="username" /><br />            Password :            <input type="password" id="password" />        </div>    </form></body></html>
```

---

Original Source: https://www.mindstick.com/blog/657/focusing-a-textbox-using-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
