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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:10:21+00:00 2026-05-16T15:10:21+00:00

In a web page I have a button when clicked it calls a JavaScript

  • 0
  1. In a web page I have a button when clicked it calls a JavaScript function.

  2. In that function I show a modal dialog box and I want to process keystrokes only at this time. That is when the modal dialog is visible.

  3. When I close the modal dialog I want to stop the keystroke processing.

  4. consider that I click a button and function sam() is called.

    function sam()
     {
      document.onkeypress = function(e) { processKeystroke(e); }
     }
    
  5. So now a function is attached to the keypress event. Whenever a key is pressed the function processkeystroke will be called.
    The function sam is called only after I display the modal dialog box.

  6. Now I am closing the modal dialog and with that I don’t want function(e) { processKes...} to be called.

  7. What should I do to remove the attached event listener from document.onkeypress.

  8. Also I would like to have alternatives for the above approach because that one I assumed of my own and I did not refer any specific documentation, so I am really going through trial and error procedure to use event handlers or listeners.

  9. So when I call function sam I want a function to be attached with the keypress event and if I call another function form example closedialog() I want that keypress listening function to be removed. Because I want to write proper code which should not consume lots of system resources.

  • 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-16T15:10:21+00:00Added an answer on May 16, 2026 at 3:10 pm

    Just write the following code to remove the handler.

     document.onkeypress = null;
    

    Since you are talking about attaching you maybe should check jquery which provides real bind (attach) and unbind (detach) for events like keypress.

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

Sidebar

Related Questions

On my web page I have a button that opens a modal jQuery dialog.
I have a web application that loads javascript on page load: $(function() { $('.modal-delete').click(function()
I have a button on a web page that when clicked connects to my
Say I have a button on a web page. Whenever that buttons is clicked,
I have a standard ASP.NET 2.0 web page with a Delete button on it.
I have a ModalPopupExtender(mpe) which will show when a asp:button is clicked. The button
I have a web page that sends email to multiple users (online distribution list).
I have a web page with some embedded Silverlight. In that Silverlight I have
I have web form in which I have to make sure that 'SUBMIT' button
I have a button on my .jsp page that I would like to act

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.