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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:14:15+00:00 2026-06-17T16:14:15+00:00

I have written a script to detect what key the user has clicked and

  • 0

I have written a script to detect what key the user has clicked and act based on the key (if its alphanumeric) but it is not working so far and has no errors.

 jQuery(document).ready(function() { 
    $("#my_field").keydown(function(event) { 
        var additional = new Array(8,9,13,27,35,36,37,38,39,46); 
        var numbers = new Array(48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105,144); 
        var letters = new Array(65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90); 
        var AllowedKeyCode = 
            (jQuery.inArray(event.keyCode, additional) >= 0) 
                || 
            (jQuery.inArray(event.keyCode, letters) >= 0) 
                || 
            ((!event.shiftKey) && (jQuery.inArray(event.keyCode, numbers) >= 0)) 
                || 
            ((event.ctrlKey) && (event.keyCode == 65 || event.keyCode == 67 || event.keyCode == 86)); 
        if (AllowedKeyCode === false) {event.preventDefault();} 
    }); 
});

Would really appreciate any help.

  • 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-17T16:14:16+00:00Added an answer on June 17, 2026 at 4:14 pm

    The ideal syntax for an array in Javascript is:

    var additional = [8,9,13,27,35,36,37,38,39,46];
    

    As opposed to:

    var additional = new Array(8,9,13,27,35,36,37,38,39,46);
    

    The issue might be that you have no return action. It is quite tricky to see in what you have posted.

    Try changing:

    event.preventDefault();
    

    to

    return false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a script which works, but I'm guessing isn't the most efficient.
I have written a Perl script for the following bioinformatics question, but unfortunately there
I need to detect whether the user has pressed the dot key in the
I have written a script in robotium which works just fine, but our application
I have written a script that on execution lets the user record a message
i have written a script that prints a XML file to the screen but
I have written a script for converting SVG to PNG which is working pretty
I have written a script that saves the output in a Perl script, but
I have written this script based on other scripts i have read about, and
I have written a script which dynamically creates a html table based off server

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.