Topic: new on Xajax

I have differents tutorial some referenced to 0.2 and the one here referenced to 0.5 but none had work on my page. I need some help, I have a form to insert new employees on a database, I need to validate if current emp code is alreade on database, so I did following function

<?
require('xajax_core/xajax.inc.php');
$objAjax = new xajax();
$objAjax->register(XAJAX_FUNCTION,'checkEmpCod');

function checkEmpCod($cod)
{
    $cod=str_pad($cod,8,"0",STR_PAD_LEFT);
    include('includes/conecta.php');    //connect to database
    $query = "SELECT codemp from empleados WHERE codemp = '$cod'";
    $result = mysql_query($query, $connection) or die ("Error in query: $query. " . mysql_error());
    if (mysql_num_rows($result) == 1)
    {
        $strerror="Empleado Ya Existe";
    }
    else
    { $strerror="";       
    }
       
    $objResponse = new xajaxResponse();
    $objResponse->assign("chkcod", "innerHTML", $strerror);
    return $objResponse;
}
$objAjax->processRequest();
printJavaScript();
?>

here is my html call

<td>codigo:</td>
<td><input type="text" name="codemp" id="codemp" style="empleado"  onchange="$objAjax_checkEmpCod()" /></td>
<td><p id="chkcod"></p></td>

any idea what is my problem? please help me.

Re: new on Xajax

Hi,
Yes it is necromancy...
But the solution can be cleared easily:

False:

$objAjax->processRequest();
printJavascript();

True

$objAjax->processRequest();
$objAjax->printJavascript();

Remember "printJavascript()" is a $objAjax's function.

Then, always try to put this function at the body's end of your Html code.
Like that:

<?php
$objAjax->printJavascript();
?>
</body>

or between <head></head>, but prefer the first solution

<head>
<?php
$objAjax->printJavascript();
?>
</head>

Your call is false too:

<td><input type="text" name="codemp" id="codemp" style="empleado"  onchange="$objAjax_checkEmpCod()" /></td>

Try this:

<td>
<input type="text" name="codemp" id="codemp" style="empleado"  onchange="xajax_checkEmpCod();" />
</td>