Results 1 to 2 of 2

Thread: JQuery trigger() not working

  1. #1
    Join Date
    Jun 2008
    Thanked 0 Times in 0 Posts

    Default JQuery trigger() not working


    I'm trying to wire up the enter key to a button click and it's not working.

    The button is a login button. We'd like for the user to have the option of clicking the button or clicking enter to log in. What I'm finding is something weird: it works if the username textbox has the focus but it fails if it doesn't.

    Here's the HTML:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="AHSLearning.Login" %>
    <html xmlns="">
        <head id="Head1" runat="server">
            <title>AHS Learning</title>
            <link rel="stylesheet" type="text/css" href="CSS/Login.css?reload"/>
            <script type="text/javascript" src="Scripts/jquery-1.11.1.min.js"></script>
            <script type="text/javascript" src="Scripts/jquery-ui-1.10.4.custom.min.js"></script>
            <script type="text/javascript" src="Scripts/Login.js"></script>
            <form id="form1" runat="server">
                <div id="BodyDiv">
                    <table class="LogoTable" border="0">
                            <td class="AHSLogoCell">
                                <img src="images/AHS.png" alt="AHS Logo" border="0" />
                            <td class="EMSLogoCell">
                                <img src="images/EMS.png" alt="EMS Logo" border="0" />
                    <div id="MainContentDiv" class="MainContent">
                        <div class="AHSLearningSystem">
                            <span>AHS Learning System</span>
                        <table class="LoginTable" border="0">
                                <td class="LoginCaptionColumn">Login:</td>
                                <td class="LoginTextboxColumn"><asp:TextBox width="150px" ID="UsernameTextbox" ClientIDMode="Static" 
    runat="server" autofocus></asp:TextBox></td>
                                <td class="LoginCaptionColumn">Password:</td>
                                <td class="LoginTextboxColumn"><asp:TextBox width="150px" ID="PasswordTextbox" ClientIDMode="Static" 
    runat="server" TextMode="Password"></asp:TextBox></td>
                                <td colspan="2" style="text-align: center;"><asp:Label ID="LoginFailedLabel" class="LoginFailedLabel" 
    runat="server">Login Failed</asp:Label></td>
                        <div class="ButtonDiv">
                            <asp:Button ID="LoginButton" Text="Login" runat="server" OnClick="LoginButton_Click" 
    onclientclick="LoginButton_ClientClick(); return false;"/>
                            <br />
                            <br />
                            <input id="ChangePasswordButton" type="button" value="Change Password" />
                    <table border="0" style="width: 100%; margin-top: 200px;">
                            <td style="width: 385px;">&nbsp;</td>
                            <td style="border-top: 1px solid black;"><span class="Version">Version: 0.7</span></td>
                            <td style="width: 510px;">&nbsp;</td>
                    <asp:HiddenField ID="IsLoggedInHiddenField" Value="false" runat="server" />
                    <asp:HiddenField ID="IsLoginAttemptedHiddenField" Value="false" runat="server" />
                    <asp:HiddenField ID="IsFirstTimeLoggingInHiddenField" Value="true" runat="server" />
    And here's the javascript:

    $(function ()
        document.onkeydown = function (event)
            if (event.keyCode == 13)
    When the username textbox has the focus and the user hits enter, $("#LoginButton").trigger() results in the C# button handler logging the user in (assuming they got their credentials correct). But if the username textbox doesn't have the focus, then I get this error from the minimized JQuery script:

    0x800a138f - JavaScript runtime error: Object.prototype.hasOwnProperty: 'this' is null or undefined

    The line in the minimized JQuery is this:,"type")?b.type:b

    I've attached the JQuery file itself in case anyone's up for parsing it (It's jquery-1.11.1.min.js).

    Can anyone tell me why the call to trigger() doesn't work when the textbox doesn't have focus?
    Attached Files Attached Files

  2. #2
    Join Date
    Jun 2011
    Pearl of the East
    Thanked 2 Times in 2 Posts




Similar Threads

  1. gAjax RSS Feeds Displayer - trigger jQuery function?
    By kblm in forum Dynamic Drive scripts help
    Replies: 8
    Last Post: 05-24-2012, 10:42 PM
  2. Jquery not working in IE 8
    By mravihpcl in forum JavaScript
    Replies: 1
    Last Post: 11-14-2011, 07:42 PM
  3. jQuery Multi Level CSS Menu #2 not working in IE6 using jQuery 1.4.x
    By Rikko in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 12-28-2010, 10:57 PM
  4. How to trigger a:hover with jQuery
    By X96 Web Design in forum JavaScript
    Replies: 2
    Last Post: 04-28-2009, 07:05 AM
  5. Replies: 0
    Last Post: 04-11-2009, 08:48 AM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts