Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 873469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:56:27+00:00 2026-05-15T10:56:27+00:00

I’m somewhat curious about the "best practices" when it comes to trapping the ENTER

  • 0

I’m somewhat curious about the "best practices" when it comes to trapping the ENTER key in an HTML input tag. In IE, it’s easy. window.event.keyCode will be 13 when enter is pressed and it’s pretty straight forward. In all other browsers, an arguments object is passed into the function. However, this seems to basically force you to late-bind a function handler to the object. You can do:

myInput.onkeypress = function (args) {
   window.alert(args.keyCode);
};

However, if you wanted to do:

<input onkeypress="checkEnter()" />

Then basically checkEnter() would be called by an anonymous function (which in theory would have the argument object) which would then call checkEnter() with no parameters. I guess you could do something totally wacky like:

<input onkeypress="checkEnter(arguments)" />

I haven’t tried this but I assume it could work. It seems that this design basically says late-binding is the only reasonable approach for trapping key presses. I’m not a fan of IE in any way, but it seems to me IE got this one right and their design is superior.

Am I missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:56:29+00:00Added an answer on May 15, 2026 at 10:56 am

    As a general rule, you shouldn’t ever be specifying JavaScript functions in HTML tags anyway. Let JavaScript code define what JavaScript needs to do, and let the HTML be completely unaware of JavaScript’s existence.

    In the case of event handlers, that does indeed mean binding functions within the script, rather than in HTML tag parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.