In response to pradeep's Initial Code:

You must switch the following code snippets in your PHP file:
Code:
if(mysql_num_rows($result) > 0)
    {
        echo "-ERR";
    }
    else
    {
        echo "+OK";
    }

This is because you WANT PHP to call out an error if you have one or more results because this means you have that user name taken already in the database. If you don't have any results, you may create that username successfully, thus echo "+OK";

So this condition is met now:
Code:
if(r.indexOf("+OK") == 0)
                 {
                     oForm.submit();
                 }
the form is then submitted, otherwise you get the alert code snippet.

Tested my code to make sure.