Help on setfocus

Hi,

Can anyone help on how to focus if there is a error in the validation process.

this is my input code using ajax…


<?php
session_start();
include_once("conn.php");

$query="SELECT * FROM tblDept";
$results=mssql_query($query) or die (mssql_error());
$user=mssql_query("Select * from tblUserLevel")or die (mssql_error());;
?>
<html>
<head>
	<title>Create User</title>
<script type="text/javascript" language="JavaScript">
<!--
function ajaxFunction(adduser)
{
	var httpxml;
	try
	{
// Firefox, Opera 8.0+, Safari
	httpxml=new XMLHttpRequest();
	}
	catch (e)
	{
	//Internet Explorer
	try
	{
	httpxml=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
	try
	{
	httpxml=new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e)
	{
	alert("Your browser does not support AJAX!");
	return false;
	}
	}
}

function stateChanged() 
{
	if(httpxml.readyState==4)
	{
	document.getElementById(adduser).innerHTML=httpxml.responseText;
	}
}

function getFormData(myadduser) { 

	var myParameters = new Array(); 
	
	val="adduser="+adduser;
	myParameters.push(val);

	//// Text field data collection //
	var val=myadduser.uname.value;
	val = "uname="+val;
	myParameters.push(val);
	// End of text field data collection //

	return myParameters.join("&"); // return the string after joining the array
} 

	var url="insertuser.php";
	var myadduser = document.forms[0]; 
	var parameters=getFormData(myadduser);
	httpxml.onreadystatechange=stateChanged;
	httpxml.open("POST", url, true)
	httpxml.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	httpxml.send(parameters) 

}
//-->
</script>

</head>
<body>
<fieldset>
<legend>User Information</legend>
	<table align=center>
		<form name='myadduser' Submit="return validate(this)" action='insertuser.php' method='Post' >
			<tr>
				<td> User Name : </td>
				<th><input id="uname" name='uname' type='text' value="<?php if(isset($_POST['uname'])) echo $_POST['uname']; ?>" onBlur="ajaxFunction('username')"></th>
				<td><div id="username" ></div></td>
			</tr>
			<tr>
				<td> Password : </td>
				<th><input id="pass" type="password" name="pass" tabindex="3" ></th>
				
			</tr>
			<tr>
				<td> Re-Type Password : </td>
				<th><input id='rpass' type='password' name='rpass' tabindex='4'></th>
				
			</tr>
			<tr>
				<td> First name : </td>
				<th><input id='fname' type='text' value="<?php if(isset($_POST['fname'])) echo $_POST['fname']; ?>" name='fname' ></th>
				
			</tr>
			<tr>
				<td> Last name : </td>
				<th><input id='lname' type='text' value="<?php if(isset($_POST['lname'])) echo $_POST['lname']; ?>" name='lname' onBlur=ajaxFunction('lastname')></th>
				<td><div id="lastname"></div></td>
			</tr>
			<tr>
				<td> Email Address : </td>
				<th><input id='email' type='text' value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" name='email' onBlur=ajaxFunction('email')></th>
				<td><div id="email"></div></td>
			</tr>	
			<tr>
				<td> Department : </td>
				<td>
				<?php 
					echo "<select name='dept'tabindex='8'>";
					echo "<option selected>Select Department ";
					while($row=mssql_fetch_array($results)){
						echo "<option  value=''>$row[DeptName]</option>";
					}echo '</select>';
				?>
				</td>
			</tr>
			<tr>
				<td> User Level : </td>
				<td>
				<?php 
					echo "<select name='userlvl'tabindex='9'>";
					echo "<option selected>Select a UserLevel ";
					while($row=mssql_fetch_array($user)){
						echo "<option value=$row[UserLevel]>$row[UserLevel]</option>";
					}echo '</select>';
				?>
				</td>
			</tr>
			<th><input type='submit' name='save' value='Save'></th>
			<th><input type='reset' name='reset' value='Reset'></th>
		</form>
		<form action='home.php'>
			<th>
				<input type='submit' value='Home' tabindex='12' >
			</th>
		</form>

</fieldset>	
</table>
</body>
</html>

this is my process code…


<?php
session_start();
include_once("conn.php");
	$uname=$_POST['uname'];
	$result = mssql_query("SELECT * FROM tblUser WHERE UserName= '$uname'"); 
$msg="";
switch($_POST['adduser'])
{
	case "username":
		if (mssql_num_rows($result) > 0) {
		echo "<font seize='3' color='#FF0000'>Username Exist</font>";
		
		}
		if (empty($uname)){
		echo "<font seize='3' color='#FF0000'>Please fill the data</font>";
		echo "<script>myadduser.uname.focus()</script>";		
		}
		
	break;
	
}
?>