i press arrow key i recieve error Object html input element in the alert message
please help
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/FormsV2/Site1.Master" CodeBehind="CursorMove.aspx.vb" Inherits="SMIS2022WEB.CursorMove1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=gvCustomers] input, [id*=gvCustomers] select").on("keydown", function (e) {
var selector = $(this)[0].tagName;
if (typeof ($(this).attr("type")) != "undefined") {
selector += '[type=' + $(this).attr("type") + ']';
}
if (e.keyCode == 40) {
var next = $(this).closest("tr").next().find(selector);
if (next.length > 0) {
$(this).closest("tr").find('[id*=chkRow]').attr('checked', 'checked');
next.focus();
}
}
if (e.keyCode == 38) {
var prev = $(this).closest("tr").prev().find(selector);
if (prev.length > 0) {
$(this).closest("tr").find('[id*=chkRow]').attr('checked', 'checked');
prev.focus();
}
}
})
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div>
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Tick">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkRow" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Id">
<ItemTemplate>
<asp:TextBox ID="txtId" runat="server" Text='<%#Eval("Id") %>' onkeyup="enter(this)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%#Eval("Name") %>' onkeyup="enter(this)" AutoPostBack="true" OnTextChanged="OnNameChanged" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country">
<ItemTemplate>
<asp:TextBox ID="txtCountry" runat="server" Text='<%#Eval("Country") %>' onkeyup="enter(this)" AutoPostBack="true" OnTextChanged="OnTextChanged"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:HiddenField ID="hfRowIndex" runat="server" />
<asp:HiddenField ID="hfCellIndex" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<script type="text/javascript">
function enter(obj) {
var tr = obj.parentNode.parentNode;
var cellIndex = obj.parentNode.cellIndex;
var rowIndex = obj.parentNode.parentNode.rowIndex;
if (event.keyCode == 37) //Left
{
if (cellIndex > 0)
tr.parentNode.rows[rowIndex].cells[cellIndex - 1].getElementsByTagName('INPUT')[0].focus();
return;
}
if (event.keyCode == 38) //Up
{
if (rowIndex > 1)
tr.parentNode.rows[rowIndex - 1].cells[cellIndex].getElementsByTagName('INPUT')[0].focus();
return;
}
if (event.keyCode == 39) //Right
{
if (cellIndex < tr.cells.length - 1)
tr.parentNode.rows[rowIndex].cells[cellIndex + 1].getElementsByTagName('INPUT')[0].focus();
return;
}
if (event.keyCode == 40) //Down
{
if (rowIndex < tr.parentNode.rows.length - 1)
tr.parentNode.rows[rowIndex + 1].cells[cellIndex].getElementsByTagName('INPUT')[0].focus();
return;
}
};
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
// enter(obj);
var rowIndex = document.getElementById("<%=hfRowIndex.ClientID%>");
alert(rowIndex);
var row = document.getElementById("<%=gvCustomers.ClientID%>").rows[rowIndex + 2];
alert(row);
if (typeof (row) != "undefined") {
var celIndex = parseInt(document.getElementById("<%=hfCellIndex.ClientID%>").value);
var controls = row.cells[celIndex].getElementsByTagName("INPUT");
for (var i = 0; i < controls.length; i++) {
if (controls[i].id.indexOf("txtCountry") || controls[i].id.indexOf("txtName") != -1) {
// Focus to the next record.
controls[i].focus();
break;
}
}
}
}
});
};
</script>
</div>
</body>
</html>
</asp:Content>
Imports System.Data
Public Class CursorMove1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {
New DataColumn("Id"),
New DataColumn("Name"),
New DataColumn("Country")})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
gvCustomers.DataSource = dt
gvCustomers.DataBind()
End If
End Sub
Protected Sub OnTextChanged(sender As Object, e As EventArgs)
Dim row As GridViewRow = TryCast(TryCast(sender, TextBox).NamingContainer, GridViewRow)
hfRowIndex.Value = row.RowIndex.ToString()
hfCellIndex.Value = "1"
End Sub
Protected Sub OnNameChanged(sender As Object, e As EventArgs)
Dim row As GridViewRow = TryCast(TryCast(sender, TextBox).NamingContainer, GridViewRow)
'hfRowIndex.Value = row.RowIndex.ToString()
hfCellIndex.Value = row.RowIndex.ToString()
hfCellIndex.Value = "2"
End Sub
End Class