jQuery - Enter como Tab previnindo Submit

<< Click to Display Table of Contents >>

Navigation:  jQuery >

jQuery - Enter como Tab previnindo Submit

Previous pageReturn to chapter overviewNext page

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2.Default" %>

 

<!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></title>

</head>

<body>

  <form id="form1" runat="server">

  <asp:TextBox ID="TextBox1" CssClass="EntTab" runat="server"></asp:TextBox>

  <asp:TextBox ID="TextBox2" CssClass="EntTab" runat="server"></asp:TextBox>

  <asp:TextBox ID="TextBox3" CssClass="EntTab" runat="server"></asp:TextBox>

  <asp:Button ID="Button1" OnClientClick="alert('Button1 clicked');" runat="server"

      Text="Button1"></asp:Button>

  </form>

   

   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>

  <script type="text/javascript">

       $(document).ready(function () {

           $(".EntTab").bind("keypress", function (e) {

 

              if (e.keyCode == 13) {

                  var inps = $("input, select"); //add select too

                  for (var x = 0; x < inps.length; x++) {

                      if (inps[x] == this) {

                          while ((inps[x]).name == (inps[x + 1]).name) {

                               x++;

                           }

                          if ((x + 1) < inps.length) $(inps[x + 1]).focus();

                       }

                   } e.preventDefault();

               }

           });

       });

  </script>

</body>

</html>