i need to attach results from a jquery function. when the user types in the search field, a function is called and data is returned from my database. i can see the returned data using alert function
<input type="text" name="symbol" id="symbol" required="required" onkeyup="findmatch();">
The Jquery function called is below
function findmatch(){
var symbol= document.getElementById("symbol").value;
$.post("portfolio/searchStock.php",
{
search:symbol
},
function(data,status){
alert(data);
});
}
i need the data returned to be attached as an auto comlete, i have tried using the following within the function, i dont understand why it doesnt work
$( "#symbol" ).autocomplete({
source: data
});
The php file echoes data as below
if (isset ($_POST['search'])){
$search = $_POST['search']; if(!empty ($search)){ $query="select * from companylist where symbol like '".mysql_real_escape_string($search)."%'"; $query_run = mysql_query($query);
while ($query_row = mysql_fetch_assoc($query_run)){
$symbol = $query_row['symbol'];
echo $symbol;
}
}
}