<?php
include('connection/database.php');
require ('xajax/xajax_core/xajax.inc.php');
$xajax = new xajax();
function autocomplete($val)
{
	if($val!="")
	{
	$query=mysql_query("select * from name where name like '".$val."%'");
	$rows=mysql_num_rows($query);
	$out="<table width='100%' bgcolor='#bfbfc3'>";
	while($data=mysql_fetch_array($query))
	{
			$out.="<tr><td>".$data['name']."</td></tr>";
}
$out.="</table>";
	$objResponse=new xajaxResponse();
	$objResponse->assign('div1','innerHTML',$out);
	$objResponse->script("jQuery:$('td').click(function(){
	var a=$(this).attr('innerHTML');
    $('#name').attr('value',a);
    $('#div1').attr('innerHTML','');
  });
  $('td').mouseover(function(){
	  $(this).css('background-color','gray');
	  });
   $('td').mouseout(function(){
	  $(this).css('background-color','');
	  });
  ");
	return $objResponse;
}
else
{
	$objResponse=new xajaxResponse();
	$objResponse->assign('div1','innerHTML',"");
	return $objResponse;
}
}
$auto =& $xajax->registerFunction('autocomplete');
$auto->setParameter(0, XAJAX_INPUT_VALUE, 'name');
$xajax->processRequest();
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>Autocompleter</title>
<?php
	$xajax->printJavascript('xajax/');
?>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="a.js"></script>
</head>
<body>
	<input type="text" name="name" id="name" onkeyup='<?$auto->printScript();?>' width="180px" />
	<div id="div1" name="div1" style=" position:relative; z-index=0; left:3px; height:120px; overflow:auto; width:179px;  top:-1px; bottom:80px;" ></div>
	<span style="position:absolute; top:50px; z-index:-1;">jhlkjlkdasas</span>
</body>
</html>

Is there a question ?

(Please add code tags.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.