title: How to count string length, if length equals X, then execute code? - JavaScript
body: <p>Using JavaScript, I want to call an anonymous function that checks the length of a string for every onkeyup event. When the string length equals 9, a conditional statement will execute a block of code.  What am I doing wrong?</p>
  
  <pre><code>&lt;input type="text" id="length_test" placeholder="Enter text here..." /&gt;
  
  var length_test = document.getElementById('length_test');
  var string_value = document.getElementById('length_test').value;
  var x = 9;
  
  length_test.onkeyup = function () {
          if (string_value.length == x) {
          // execute code here...
          }
      }
  </code></pre>