Monday, May 9, 2011

Enter Key Acts As Tab Key using Javascript

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

<!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 id="Head1" runat="server">
<script language="javascript" type="text/javascript">
function testing(event,number)

{
if( event.keyCode == 13 )

{
var wow = document.getElementById(number);

wow.focus();

}

}

</script>
    <title>Making enter key work as tab for Fire Fox</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    &nbsp;<asp:Label ID="Label1" runat="server"
            Text="Make enter key work as tab for Fire Fox"></asp:Label>
        <table class="style1">
            <tr>
                <td>

                    <asp:TextBox ID="TextBox2" runat="server" onkeydown="testing(event,2)"
                        TabIndex="1"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <input id="2" type="text" tabindex="3" onkeydown="testing(event,3)" /></td>
            </tr>
            <tr>
                <td>

                    <input id="3" type="text" tabindex="2" onkeydown="testing(event,'ab')" /></td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox ID="ab" runat="server" onkeydown="testing(event,'cd')"
                        TabIndex="4"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox ID="cd" runat="server" onkeydown="testing(event,'ef')"
                        TabIndex="10"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:DropDownList ID="ef" runat="server" onkeydown="testing(event,'RadioButton1')">
                        <asp:ListItem>a</asp:ListItem>
                        <asp:ListItem>b</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:RadioButton ID="RadioButton1" runat="server" onkeydown="testing(event,'ListBox1')"/>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:ListBox ID="ListBox1" runat="server" onkeydown="testing(event,'TextBox1')"></asp:ListBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" onkeyup="testing(event,'Button1')"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="Button1" UseSubmitBehavior="false" runat="server" Text="Button" Width="166px" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

0 comments:

Post a Comment