title: field focus not working in firefox, setTimeout(function(){id.focus();},0);
body: <p>As my application runs on Firefox, and i have got problem to focus on field in Firefox i read many <a href="https://stackoverflow.com/questions/12542897/not-setting-focus-to-text-field-in-firefox">Question</a>
  here(stack overflow) in all answers i saw below code to fix this problem:</p>
  
  <pre><code>function onloadFocus(){
      setTimeout(function() {
          document.getElementById('name').focus()
      },0);
  }
  </code></pre>
  
  <p>but when you run below code which i have to implement in my application, <strong>NOTE:</strong> this is not pure code , its a demo.
  Please read comments written inside the code.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;head&gt;
  &lt;script &gt;
  function abc(id,spanId){
  var testVar = document.getElementById(id);
  var spanVar = document.getElementById(spanId);
  
  if(id.value =='') {
  spanId.innerHTML = 'value is required';
  //setTimeout(function(){id.focus();},0); //first close this line of code and execute it.
  id.focus(); // then close this line and open comment of above line run it
  return false;
  }
  
  }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;form&gt;
  &lt;lable&gt;Enter 1st value&lt;/lable&gt;&lt;input type="text" onblur="abc(this,test_s1)"/&gt;
  &lt;span id="test_s1"&gt;&lt;/span&gt;
  &lt;lable&gt;Enter 2nd value&lt;/lable&gt;&lt;input type="text" onblur="abc(this,test_s2)"/&gt;
  &lt;span id="test_s2"&gt;&lt;/span&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>when you execute code with <code>id.focus();</code> its working fine(some time in firefox, but working well in all other browsers e.g: chrome), but when you run code with <code>setTimeout(function(){id.focus();},0);</code> you will see a infinite loop of focus will start on both text fields. How can i fix this situation??
  please check above code in both browsers FIREFOX and CHROME.
  If you are not understanding my question please let me know..</p>