title: How can I check duplicate username in a form without posting form and set focus on username if it already exists?
body: <p>I have a form to filled out by user. Its user registration form. I want that when user fill username text,my form should search for user name whether it exist or not.If it exist then username text field should get focus.My database table name is users and it contains column named as id,username,password,status. 
  Here is my code.</p>
  
  <pre><code>&lt;form name="user" action="#" method="post"&gt;
      &lt;label&gt;Username&lt;/label&gt;
      &lt;input type="text" maxlength="25" name="username" /&gt;
      /*here i want to check from my db table weather username exists or not*/
      &lt;label&gt;Password&lt;/label&gt;
      &lt;input type="password" maxlength="25" name="password" /&gt;
      &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I can do it when user submits the form.But my requirement is to check value with out submitting form and username should get focus.
  and in php I have following code</p>
  
  <pre><code>&lt;?php
      mysql_connect("localhost","root","") or die(mysql_error());
  
      mysql_select_db("test") or die(mysql_error());
      $username = $_REQUEST['username'];
      $query=mysql_query("SELECT * from user where name='$username'");
      $row=mysql_num_rows($query);
      if($row==1){
          echo "true";
      } else {
          echo "false";
      }
  ?&gt;
  </code></pre>