jQuery auto focus.

In this post we will see how to set focus automatically on input control. This is done using .focus() function in jQuery.

jQuery auto focus example

<script type="text/javascript">
   $(function () {
        $("#fName").focus();
   });
</script>

.focus()function is simple and we can call it on input control on which we need to set focus.

Below is simple full example of .focus() in jQuery

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#fName").focus();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="fName"/>
<input type="text" id="lName"/>
</div>
</form>
</body>
</html>

Related Posts:

  • Get radio button value in jQueryWhen using radio buttons in web application we need to get value of radio buttons at clientside. We can use jQuery to get radio button value in jQuery… Read More
  • Assign value using jQueryIn asp.net applications we need to assign value in javascript or jQuery to the controls like label or hiddenfield. We will see sample code that assign… Read More
  • Image click event in jquery In this post we are going to see how to get click event of image. This can be done by using either id jquery selector or css selector. We will see … Read More
  • jQuery Tabs - UIjQuery UI libaries provied good controls. jQuery UI contains tab control that is used to show tabed formatted data. We will see example how to show jq… Read More
  • jQuery validate form empty fieldsIn Web forms we need to validate fields on the form to check field should not be empty. For example for login form we need to validate textboxes for u… Read More

0 Comments :

Post a Comment