views:

52

answers:

1

Hi,

i've setup an autocomplete field that searches my database which works fine:

$("#autocomplete input#lookupAccount").autocomplete("lib/php/autocomplete_backend.php", {
    width: 300,
    selectFirst: false,
    delay: 250 });    

When a user clicks on a result I want to refer them to another page depending on what they've been clicking. In the documentation I find the following:


Search Page Replacement

An autocomplete plugin can be used to search for a term and redirect to a page associated with a resulting item. The following is one way to achieve the redirect:

var data = [ {text:'Link A', url:'/page1'}, {text:'Link B', url: '/page2'} ];
$("...").autocomplete(data, {
  formatItem: function(item) {
return item.text;
 }
}).result(function(event, item) {
  location.href = item.url;
});

So i need to return the following from my PHP file : {text:'link A', url:'/page1'},...

But my PHP file now returns

$returnData = "<ul>";
if(isset($results)){
for($j=0; $j < count($results); $j++){
 if($results[$j][0] == "account"){
 if($j % 2){
 $returnData .= "<li>".$results[$j][1]."<br /><i>".$results[$j][2].", ".$results[$j][3]." ".$results[$j][4]."</i></li>";
 } else {
   $returnData .= "<li style=\"background: blue\">".$results[$j][1]."<br /><i>".$results[$j][2].", ".$results[$j][3]." ".$results[$j][4]."</i></li>";
  } 
   } else {
   $returnData .= "<li style=\"background: yellow\"><i>".$results[$j][1]."</i> (".$results[$j][2].")</li>";
    }
    }
     $returnData .= "</ul>";
     echo $returnData;
     } else {
      echo "Sorry geen resultaten!";
     }

So it loops through an array and returns an li value depending on what it finds in the array. How can I match that with: {text:'link A', url:'/page1'}???

A: 

Hi All,

I m using autocomplete from

http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

i managed to get data from server in below form but in autocomplete list i dont see spaces that i added after supplier , i even tried removing trim all over from the script but that does not solved my issue.Please suggest.

Exon: Supplier HJR/VAKJ -1

Jos