By 06/02/2014 3 Comments

How To Auto Focus the First ASP.NET TextBox using jQuery

What is auto focus

  • When a user opens a new website for registration, he / she always see that the cursor is placed in first text box or text field, that is called auto focus
  • It can be easily achieved by using JQuery

Following code describe that how to auto focus a text box contol / text field in using JQuery

JQuery Code snippet

<script type="text/javascript" src="Scripts/jquery-1.8.2.js"></script> <!--- import jquery library --->
        $(document).ready(function() { // method called, when document loaded by browser

            $("input:text:disabled").css("background-color", "gray"); // set grey background color by css method of text boxes, which is disabled

           $("input:text:enabled:first").focus(); // :enabled:first to the TextBox, to set focus on the TextBox that is enabled, which in our case is the third textbox (TT_TextBox3), focus() method are used for auto focusing in given text box



ASP.NET Code snippet

<!-- Following code renders the 4 text fields and a label control on browser --->

<asp:Label runat="server" Text="Auto Focus the First TextBox that has Enabled=true"></asp:Label>
        <asp:TextBox ID="TT_TextBox1" runat="server" Text="" Enabled="false" /><br /><br />
        <asp:TextBox ID="TT_TextBox2" runat="server" Text="" Enabled="false" /><br /><br />
        <asp:TextBox ID="TT_TextBox3" runat="server" Text="" /><br /><br />
        <asp:TextBox ID="TT_TextBox4" runat="server" Text="" /><br /><br />

Posted in: ASP.NET, jQuery

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .