title: How to make Javascript focus() method work in onBlur event for input text box?
body: <p>For me Javascript <code>focus()</code> method is working fine if I use it with a button and onClick event, but with <code>onBlur</code> from a text box, it is not working. Can anyone guide me on this?</p>
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
  function displayResult()
  {
  var inp1=document.getElementById(&quot;text1&quot;).value;
  var inp2=inp1.length;
  if(inp2==0)
  {
  alert(&quot;Field 1 cannot be left Empty&quot;);
  //document.getElementById(&quot;text1&quot;).value=&quot;&quot;;
  document.getElementById(&quot;text1&quot;).focus();
  }
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;input type=&quot;text&quot; name=&quot;text1&quot; id=&quot;text1&quot; onBlur=&quot;displayResult();&quot;/&gt;
  &lt;input type=&quot;text&quot; name=&quot;yext2&quot; id=&quot;text2&quot; /&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>