javascript function for invoking button click event

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>javascript function for invoking btnclick event</title>

    <script language="javascript" type="text/javascript">
        function TrigButton() {
            if (window.event.keyCode == 13) {
                if (document.getElementById('txt').value.length > 0) {
                    document.getElementById('bt').focus();
                    document.getElementById('bt').click();
                }
            }
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:textbox id="txt" runat="server" onkeydown="TrigButton()"></asp:textbox>
        <asp:button id="bt" runat="server" text="Button" onclientclick="javascript:alert('Button Triggered');"
            onclick="bt_Click" />
    </div>
    </form>
</body>
</html>

2 comments:

  1. Its working fine........

    It solved my problem..

    Thanks a lot

    ReplyDelete