title: Javascript alert messages in infinite loop
body: <p>Alert boxes in infinite loop, here I am trying to put a popup alert message on 2 consecutive fields so they cannot be left blank, I know why it is happening - because when onblur event of 1st function is launched it gives focus to second one &amp; when it jumps back to first one onblur of 2nd textfield is launched. </p>
  
  <p>I know validation would be best when done at the form level, but this is the requirement I got.</p>
  
  <p>Any help?</p>
  
  <p>Javascript code</p>
  
  <pre><code>function x()
  {
     if( document.getElementById("1").value.length==0)
     {
        alert('1 is required');
        document.getElementById("1").focus();
     }
  }
  
  function y()
  {
     if(document.getElementById("2").value.length==0)
     {
        alert('2 is required');
        document.getElementById("2").focus();
     }
  }
  </code></pre>
  
  <p>HTML code</p>
  
  <pre><code>&lt;input type="text" name="City Name" id="1" onblur="javascript:x();"&gt;
  &lt;input type="text" name="Kitty Name" id="2" onblur="javascript:y();"&gt;
  </code></pre>