SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Prototype.js Event.observe not working?

    Ok, I've been trying to figure out why this doesn't work for a couple of days on the prototype user mailing list with no luck.

    Can any of you gurus figure out what's busted?

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    <title>Untitled</title>
        <script language="JavaScript" type="text/javascript" src = "scriptaculous/prototype.js"></script>
        <script language="JavaScript" type="text/javascript" src = "scriptaculous/scriptaculous.js"></script>
        <script language="JavaScript" type="text/javascript">
            function catchEnterKey(e) {
                if (!e) { e = window.event; }
                alert('ok');
            }
            //-->
        </script>
    </head>
    <body>
    <form id="loginForm" method="POST" action="#">
      <div>
        <label for="loginId">Username</label>
        <input id="loginId" type="text" name="loginId" value="" />
      </div>
      <div>
        <label for="password">Password</label>
        <input id="password" type="password" name="password" value="" />
      </div>
      <div id="uaButtonDiv">
        <input id="loginButton" type="submit" name="login" value="Login" class="uauthLogin" />
      </div>
    </form>
    <script language="JavaScript" type="text/javascript">
    <!--
    Event.observe('loginButton', 'click', 'catchEnterKey');
    
    //the following lines work
    //var button = document.getElementById('loginButton');
    //button.onclick = catchEnterKey;
    //-->
    </script>
    
    </body>
    </html>
    When i rund this in FF2 I get the following error from FireBug:
    uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: file:///withheld/scriptaculous/prototype.js :: anonymous :: line 2999" data: no]

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you don't need (or want) quotes around the function name:
    Code:
    Event.observe('loginButton', 'click', catchEnterKey);

  3. #3
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True that, fixed it right up.

    You are officially the man gjones, unless your a woman of course!


Bookmarks

Posting Permissions

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