title: How to set Focus in a textfield
body: <p>I have a sign up form. I want to implement some validation at client end itself. I am using a button to submit a form.   </p>
  
  <pre><code>&lt;button onclick="check_fields();"&gt;&lt;/button&gt;
  
   function check_fields() {          
         if(document.contact_form.name.value=='')                                                     
             document.contact_form.name.focus();
         else 
             document.getElementById("contact_form").submit();    
     }
  </code></pre>
  
  <p>Focus is not happening, instead form is successfully submitting. 
  Please help.</p>