title: alert when focus is in text box only
body: <p>I am getting an alert when i skip the text box but an alert is also coming wherever I click on page. How can I show an alert when the focus will be on the text box? The alert is also coming even when I open a new tab. Is there a way to solve this? Many thanks.</p>
  
  <pre><code>$(function() {
      $("input").blur(function() {
      if(!this.value) {
        alert("Text box " + ($(this).index() + 1) + " cannot be empty.");
        this.focus(); //Keep focus on this input
      }
  });
  </code></pre>
  
  <p>body section</p>
  
  <pre><code>&lt;input type="text" id="textbox1"/&gt;
  &lt;input type="text" id="textbox2"/&gt;
  &lt;input type="text" id="textbox3"/&gt;
  &lt;input type="text" id="textbox4"/&gt;
  </code></pre>