Te dejo un ejemplo completo, con formulario y todo para que lo pruebes, a mi no me genera ningún error.
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script>
function isEmpty(inputVal)
{
inputStr = inputVal.length
var contsps = 0 // contador de espacios en blanco
for (var i = 0; i < inputStr ; i++)
{
var oneChar = inputVal.charAt(i)
if (oneChar == " ")
{
contsps = contsps + 1
}
}
if (contsps == inputStr)
{
return true
}
else
{
return false
}
}
function validaForm()
{
var user = document.getElementById('username');
var pass = document.getElementById('password');
if (isEmpty(user.value))
{
alert("El user no debe estar vacío");
return false;
}
if (isEmpty(pass.value))
{
alert("El pass no debe estar vacío");
return false;
}
}
</script>
<body>
<form action="validar.php" method="POST" onsubmit="return validaForm();">
<table cellpadding="0px" cellspacing="0px">
<tr>
<td>login: </td>
<td><input type="text" name="username" id="username" maxlength="30" size="25" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>password: </td>
<td><input type="password" name="password" id="password" maxlength="30" size="25" /></td>
<td> </td>
<td><input type="submit" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>