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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:24:27+00:00 2026-06-18T06:24:27+00:00

I am creating a conversion web app to teach myself Javascript. The user can

  • 0

I am creating a conversion web app to teach myself Javascript. The user can input data with a number pad (basically a calculator without the operators). I also set up a function to detect keystrokes (1-9) which insert data just like the number pad. And also character ‘c’ which clears all data

My problem is that I also have a search field (which uses auto complete to enable the user to search for other conversions). I dont’ want the user to search for something using the ‘c’ or number keys, and have it enter data into both the number pad, and search field.

My idea was to create a if statement to determine if the search field was active (focused), and if it was to change a variable (enabled) to false, thus disabling the keystroke detection.

The problem I am having is that the function holding the if statement with the focus attribute is not working.

If my rambling made no sense hopefully the code will clear things up.

Here is the if statement with the focus attribute

$(document).ready(function(){
    if($(':focus').attr('#searchInput') == 'input')){
        enabled === false;
    }
});

Here is the code for key stroke detections (I omitted the redundant parts to save space

document.onkeydown = function(event){
    var key = event.charCode || event.keyCode;
    if(enabled === true){
        if(key === 67){
            clearInput(input); //Clears form input (input is my form ID)
        }else if(key === 48){
            writeInput(input, zero); //Zero is a var equaling 0
        }
        ...
    }else{
        return false; //if enabled is false don't detect keystrokes
    }
};

Any help would be greatly appreciated. If anything doesn’t make sense I will be happy to explain (or edit the post.)

  • 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-18T06:24:28+00:00Added an answer on June 18, 2026 at 6:24 am
    $(document).keyup(function(e){
       if($('#searchInput').is(':focus')) {
          return ; // search field is focused, ignore other part of function
       }
       var key = e.which;
       // do your code here
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a web app that I would like to be able to translate
I am creating an 0800 diverting app which allows the user to use his/her
I am creating a file conversion console app to change xml files generated by
I'm currently building a semi-complicated calculator which is basically a conversion from an Excel
I am busy creating a currency Module for my web app, I am using
I'm currently creating both the client and server app using ActiveResource for web servicing.
I am creating a SQL Server database programmatically during a conversion. If the conversion
Creating an a app, where I store bunch of photos in the drawable folder,
Creating a google map with store locations within 50 miles of user entered address.
(creating a separate question after comments on this: Javascript redeclared global variable overrides old

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.