Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Updated 18-Jan-13 6:08am
v2
Comments
adriancs 25-Nov-14 8:35am    
You are too lazy to even search in google.
You should not be helped.

Hi,
Find your solution below.
XML
<%@ 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>
 
Share this answer
 
v2
Comments
[no name] 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 23-Sep-14 5:58am    
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
silvan silvan 25-Jun-18 2:33am    
after page load its not working..how to do that situation
 
Share this answer
 
Comments
Adam R Harris 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 23-Jan-13 10:29am    
Thank you for proving my point.
adriancs 25-Nov-14 8:36am    
He is too lazy to search in google and yet lie.
He should not be helped.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900