Need some quick help. Please see my code below. When I start typing in the search box the Suggestions are shown below as a table but i need them like Google suggest(live search).
Please help me on this.
Code (text):
HTML FILE
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox,
Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new
ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4
&& xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<input type="text"
id="txt1" size="30"
onkeyup="showUser(this.value)" autocomplete="off" />
<div
id="livesearch"></div>
</form>
<br />
<div
id="txtHint"><b>Your group will be listed
here</b></div>
</body>
</html>
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost',
'root', '');
if (!$con)
{
die('Could not connect: ' .
mysql_error());
}
mysql_select_db("needsesearch",
$con);
$sql="SELECT title FROM
`jos_sections` WHERE title like '%".$q."%' ";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
</tr>";
while($row =
mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" .
$row['title'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
No comments:
Post a Comment