title: Jquery detect input focus
body: <p>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 </p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>The problem I am having is that the function holding the if statement with the focus attribute is not working.</p>
  
  <p>If my rambling made no sense hopefully the code will clear things up.</p>
  
  <p><em>Here is the if statement with the focus attribute</em></p>
  
  <pre><code>$(document).ready(function(){
      if($(':focus').attr('#searchInput') == 'input')){
          enabled === false;
      }
  });
  </code></pre>
  
  <p><em>Here is the code for key stroke detections (I omitted the redundant parts to save space</em></p>
  
  <pre><code>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
      }
  };
  </code></pre>
  
  <p>Any help would be greatly appreciated. If anything doesn't make sense I will be happy to explain (or edit the post.)</p>