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 3212866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:52:57+00:00 2026-05-17T14:52:57+00:00

I have an <input> which has an onkeydown inline event handler. In this handler,

  • 0

I have an <input> which has an onkeydown inline event handler. In this handler, I’d like to call a function and pass a special parameter to it – the event data.

When I want to handle events (e.g. onmousemove) for the whole document, I use the following code:

document.onmousemove=function(e) {
// here I can make a good use of the 'e' variable,
// for example extract the mouse coordinates from it
}

And it works (although I don’t know where the e variable – event data – comes from).
But this time I want to use the function only for the <input> mentioned above.
I need to pass the event data to the function so it can get the pressed key’s code. And I want to do it in that inline event handler. I’ve created a function:

function myfunc (e) {
    var evt=window.event?event:e;
    var code=evt.keyCode;
    alert (code);
}

and tried all of these methods:

<input onkeydown="myfunc(this)">

<input onkeydown="myfunc(this.onkeydown)">

<input onkeydown="myfunc(onkeydown)">

But none of them worked, the alert window kept displaying “undefined”.
I looked for a solution to my problem in Google, but didn’t find anything that could help me solve it.

  • 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-17T14:52:58+00:00Added an answer on May 17, 2026 at 2:52 pm

    <input onkeydown="myfunc(event)">

    function myfunc (e) {
        e = e || window.event;
        var code = e.keyCode;
        alert (code);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My site has an input box, which has a onkeydown event that merely alerts
We have an Access DB which has a set of local tables and input
I have a streaming input which has repeated values. I can use any data
I have an input field which has a placeholder text. I want one word
Good day members, I have an input file which has rows of numerical digits
I have an input text field which has style: visibility: visible or style: visibility:
I have input data coming from a flat file which has english, japanese, chinese
I have a webpage which has 10 separate text input spaces. I need to
I have an input which is in UTF16LE encoding. By the time this input
I have a dynamic data table in JSF which has multiple input elements which

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.