V24s

"Get Updates : Subscribe to our e-mail newsletter to receive updates........" "Good Luck frnds" Admission 2018 Application Form 2018 Colleges Entrance Exam 2018 Results 2018 Notification 2018 University Educational Jobs 2018 Government Jobs 2018

Search This Blog v24s guys

Follow by Email

15 April, 2013

jQuery Set Focus on First Textbox during Page load or Particular Textbox on Page load

Introduction

Here I will explain how to set focus on first or particular textbox during pageload using 
jQuery in asp.net.

Description: 
   
In previous articles I explained jQuery Countdown timer script example, 
jQuery Increase or Decrease font size of website, Redirect to another page after some time delay, jQuery slideUp slideDown toggle effectsand many articles relating to JQuery and asp.net. Now I will explain how to set focus on first or particular textbox during pageload using jQuery in asp.net.

To set focus on first textbox we need to write the code like as shown below

<script ype="text/javascript">
$(document).ready(function() {
$('input:text:first').focus();
})
</script>

If you want to set focus on particular textbox then use textbox id for that we need to write the code like as shown below

<script type="text/javascript">
$(document).ready(function() {
$('#txtUserName').focus();
});
</script>
If you want to see this with complete example check below code

Example


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Set focus in first textbox or particular textbox during page load</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
// Set focus in first textbox during page load
$('input:text:first').focus();
// Set focus in location textbox when click on button
$('#btnClick').click(function() {
$('#txtLocation').focus();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<b>UserName:</b> <input type="text" id="txtUserName" /><br />
<b>Location:</b> <input type="text" id="txtLocation" /><br />
<input type="button" value="Click to Set Cursor" id="btnClick" />
</div>
</form>
</body>
</html>
Live Demo

To check Live demo check below textbox and click on button to set focus in location textbox



UserName: 
Location:    
                   

Post a Comment

Popular Posts

Recent Posts

Google Analytics