I am trying to create a search function where the search results are updated as the user types. I am guessing I will have to use Javascript but have hit a dead end really, don't know where to progress from here....
<?PHP
//This method prints out a JavaScript function for updating the values in the client listbox
function PrintUpdateFunction(){
$searchtext = "document.client_search.searchtext";
$results = "document.client_search.client_id";
/*
** Start the function
*/
print("function updateResults()\n");
print("{\n");
/*
** Add code to clear results
*/
print("\t//clear previous results\n");
echo "while (".$results.".options.length) {\n";
echo "\t".$results.".options[0] = null;\n";
echo "}\n";
//get list of clients
$queryc = "SELECT name as company, clientid from tbl_clientdetails where ".
"name like '%".$searchtext."%' ORDER BY name ASC LIMIT 30";
$rlist = mysql_query($queryc);
$num_rlist = mysql_num_rows($rlist);
//loop over each record and place in result box
$count=0;
while($objc = mysql_fetch_object($rlist))
{
$cvalue = $objc->clientid;
$cname = $objc->name;
$optionValue = $cvalue;
$optionLabel = $cname;
echo $results . ".options[" . $count . "] = new Option(\"". $optionLabel. "\", \" ". $optionValue. "\");\n";
$ecount++;
}
print("}\n\n");
?>
The search page calls PrintUpdateFunction() and has a text box for the user input ($searchtext) and the results are displayed in a list box of a set size. The query doesn't do anything because I am not sure how to get the value using php, am I going to have to execute the query using javascript? I am way out of my depth, please help!