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

  • SEARCH
  • Home
  • 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 8126191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:04:25+00:00 2026-06-06T07:04:25+00:00

I have a page where I need to capture input from a user after

  • 0

I have a page where I need to capture input from a user after they click on a part of the page (a div). Here’s my code:

<html>
<body>
<div style="background-color: lightpink" onkeydown="onkeydown1(event)" tabindex="-1">
click me, then press a key
</div>

<script type="text/javascript">
function onkeydown1(event)
{
    alert(event.charCode);
}
</script>
</body>
</html>

See it in action: http://jsfiddle.net/WRwBF/

It took me the longest time to get this far because FireFox doesn’t by default allow a div to “have focus.” Eventually I found out that setting the tabindex for the div allows it to be in focus and the onkeydown event works.

My problem now is that when I click in the div and press a key, the value “0” is returned regardless of what key is pressed. Why would this be happening, and how can I fix it?

I would very much appreciate any guidance you might be able to give!

  • 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-06-06T07:04:27+00:00Added an answer on June 6, 2026 at 7:04 am

    Read http://unixpapa.com/js/key.html.

    Summary: using the keypress event is the only way to get reliable information about the character typed. The following will be good enough to get you the character typed in most situations:

    var charCode = (typeof event.which == "undefined") ? event.keyCode : event.which;
    alert("Character typed: " + String.fromCharCode(charCode));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context What we need is to capture some user input (formatted text) from a
I have a page that I need to design in PhP/Html/Java/CSS that has to
I need something simple; I have page where a user clicks an author to
I have an android application in which I need to get the HTML code
I need to capture user's X.509 certificates from their cards and map to a
I have a PHP page I need to limit execution access of to only
I have a page where I need SWFObject, jQuery and Google Maps API. I
have downloaded page by webbrowser and need to get mail address. But it is
i have a page like: and i need to print to pdf ( or
I have a timed page that I need to use to submit a form

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.