title: Checking if a textbox is empty in Javascript
body: <p>This is my code which was supposed to raise an <code>alert</code> message if the textbox is left empty:</p>
  
  <pre><code>function a(id)
  {
      var n=document.getElementById(id).value;
      if (n.length &lt; 1)
      {
          window.alert("Field is blank");
          return false;
      }
  }
  </code></pre>
  
  <p>The bug I'm getting is that the field is not getting verified <code>onChange</code> the first time. But when the text box is filled with some data and erased, now the <code>OnChange</code> fires, and the <code>alert</code> message is displayed. How can I fix this bug?</p>