Home > Forum > ASP.NET > if i press the enter key i need to show the cursor in another textbox

if i press the enter key i need to show the cursor in another textbox

by celv   on Oct 20, 2014   Category: ASP.NET  |  Views: 1505    |  Points: 5   |  Bronze 
  Reply
if i press the enter key i need to show the cursor in another textbox1 if i press enter key again show the cursor in textbox2. but i write code in textbox2 (Text change event) and i have radiobutton i press the enter key need to select the radio button in asp.net

Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 
  Re :if i press the enter key i need to show the cursor in another textbox   
by Thamil
on Oct 20 2014 5:24AM
Points : 10
Gold 
Hi celv,

Please refer the below sample code to focus the next control when press enter key
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="LearnDev.test" %>
<!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">
<title>Sample page</title>
<script type="text/javascript">
function NextFocus(ctrl_Val,_key) {
if (_key == 13)
{
var Nxt_Cntrl_Focus = document.getElementById(ctrl_Val);
Nxt_Cntrl_Focus.focus();
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" onkeydown="return NextFocus('TextBox2',event.keyCode);"></asp:TextBox><br />
<asp:TextBox ID="TextBox2" runat="server" onkeydown="return NextFocus('TextBox3',event.keyCode);"></asp:TextBox><br />
<asp:TextBox ID="TextBox3" runat="server" onkeydown="return NextFocus('TextBox4',event.keyCode);"></asp:TextBox><br />
<asp:TextBox ID="TextBox4" runat="server" onkeydown="return NextFocus('btnSubmit',event.keyCode);"></asp:TextBox><br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>


Thanks.
  Re :if i press the enter key i need to show the cursor in another textbox   
by celv
on Oct 21 2014 12:09AM
Points : 10
Bronze 
<tr> <td align="left"> <asp:Label ID="Label4" runat="server" Text="ID" ForeColor="White"></asp:Label> </td><td><asp:TextBox ID="TextBox3" runat="server" ontextchanged="TextBox3_TextChanged" AutoPostBack="True" onkeydown="return NextFocus('Present',event.keyCode);"></asp:TextBox></td></tr>

<tr><td align="left"><asp:Label ID="Label2" runat="server" Text="Status" ForeColor="White"></asp:Label> </td><td><asp:RadioButton ID="Present" runat="server" Text="Present" GroupName="se" ForeColor="White" oncheckedchanged="Present_CheckedChanged" AutoPostBack="True" onkeydown="return NextFocus('Button1',event.keyCode);" /> </td></tr>



it never focus the radio button and then radio button never focus the button

Recent Post

Latest Posts