title: focus textfield if javascript validation failed
body: <p>I've this code:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript"&gt;
              function validate(){
                  var name=document.frm.name.value;
                  if(name.indexOf("A")==0){
                      alert(name);
                  }
              }
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form name="frm" action="test.php"&gt;
              Enter name:&lt;input type="text" name="name" onblur="validate()"/&gt;
              Enter e-Mail:&lt;input type="text" name="email" onblur=""/&gt;
              &lt;input type="submit"/&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In above code, I'd tried to validate textfields when they lose focus. The script working fine if the name starts with <code>A</code>. But I want if the user enter different name which doesn't start with <code>A</code> it will return the focus to the textfield <code>name</code>. For that I'd written this script:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var name = document.frm.name.value;
      if(name.indexOf("A") == 0){
          alert(name);
      }else{
          document.frm.name.focus();
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>then it doesn't works.  </p>
  
  <p>Anybody could help with that what should I do to request focus of textfield <code>name</code>?<br>
  I've only a little knowledge of <code>javascript</code>.</p>