Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
My webform has 3 textboxes.
I want to move through textboxes by pressing Enter Key.
using asp.net or javascript or anything else.
 
I didn't find anything in google that works.
 
Please help
Posted 18-Jan-13 6:05am
Edited 18-Jan-13 6:08am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
Find your solution below.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TextBoxEnterbox.aspx.cs" Inherits="TextBoxEnterbox" %>
 

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head runat="server">
 
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
 
<title></title>
 
<script type="text/javascript">
 

 
$(document).ready(function() {
 
// Setting focus on first textbox

$('input:text:first').focus();
 
// binding keydown event to textbox

$('input:text').bind('keydown', function(e) {
 
// detecting keycode returned from keydown and comparing if its equal to 13 (enter key code)

if (e.keyCode == 13) {
 
// by default if you hit enter key while on textbox so below code will prevent that default behaviour

e.preventDefault();
 
// getting next index by getting current index and incrementing it by 1 to go to next textbox

var nextIndex = $('input:text').index(this) + 1;
 
// getting total number of textboxes on the page to detect how far we need to go

var maxIndex = $('input:text').length;
 
// check to see if next index is still smaller then max index

if (nextIndex < maxIndex) {
 
// setting index to next textbox using CSS3 selector of nth child

$('input:text:eq(' + nextIndex+')').focus();
 
}
 

 
}
 
});
 
});
 
</script>
 
</head>
 
<body>
 
<form id="form1" runat="server">
 
<div>
 
First Name: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 
Last Name: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
 
Email: <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
 
Confirm Email: <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
 
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
 
</div>
 
</form>
 
</body>
 
</html>
  Permalink  
v2
Comments
Sourav Sarkar-SS2 at 18-Jan-13 13:50pm
   
Thank you so much, sir!
I am Really grateful to you.
You are just great.
Awesome work.
Thanks you once again
amitkumar5734 at 15 hrs ago
   
sir in this question we have only textboxses just provide me a solution if we have some button or radio button then what i have to do
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Adam R Harris at 18-Jan-13 14:49pm
   
You win the prize for most ungrateful Code Project user.
Had you actually clicked through the link and read it, it would have given you basically the same solution.
It is users like you that bring down the quality of this site, once again if you open the link i posted and read that thread you will see that it is essentially the same solution that was posted in Solution 2.
 
You're an ass and i will make sure i skip over any future questions you have.
Adam R Harris at 23-Jan-13 10:29am
   
Thank you for proving my point.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 520
1 mhegazy94 460
2 Ravi Bhavnani 230
3 Kornfeld Eliyahu Peter 185
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 7,205
1 OriginalGriff 6,801
2 CPallini 5,350
3 George Jonsson 3,644
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100