This might be very easy for some of you but very hard for me since first time doing it.
By looking at some examples on the web, I ended up with the code below for auto-suggestion example but the code doesn't work.
Thanks
HTML
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('#textbox_postcode').autocomplete(
{
source: 'search-db.php',
minLength: 3
});
});
</script>
</head>
<body>
<form action="search.php" method="post">
<input type="text" id="textbox_postcode" value="" /> <input type="submit" value="Search" />
</form>
</body>
</html>
PHP
$keyword = ltrim(strtolower(strip_tags($_GET['keyword'])));
if (! $keyword) return;
$host = 'localhost'; $user = 'root'; $pswd = ''; $dtbs = 'geomaps';
$host_conn = mysql_connect($host, $user, $pswd); $dtbs_conn = mysql_select_db($dtbs);
$return = array();
$sql = "SELECT id, postcode FROM postcodes WHERE postcode LIKE '$keyword%' ORDER BY postcode"; $run = mysql_query($sql);
if (@mysql_num_rows($run) == 0) return;
while ($records = mysql_fetch_array($run, MYSQL_ASSOC)) { $return[] = $records; }
echo json_encode($return);
Uncaught TypeError: Object [object Object] has no method 'autocomplete'. When I type something, nothing happens. - BentCoderjquery-ui.css,jquery.min.jsandjquery-ui.min.jsto my html. I changedecho json_encode($return);withreturn json_encode($return);(same with echo). Error is gone but I still cannot get the result from database. Any idea? - BentCoder