I'm sort of trying to do the same thing and I got it working, to an
extent. The only problem is that I'm not using JSON and when I tried
to use JSON, it didn't display any search results, even though Firebug
showed the results were working.

I'm using a php backend.

Here's what I have in my javascript (formatItem is not working in
this, but I would like for it to work, without it, I get a link in the
results drop down):
var searchurl = $("#speakerformsearch").attr('action');
                $("#speakersearchinput").autocomplete(searchurl,{
                        formatItem: function(item){
                                return item.text;
                        }
                }).result(function(event, item){
                        location.href = item.attr('href');
                });

My php code:

while($speaker = mysql_fetch_assoc($speaker_query)){
        if (strpos(strtolower($speaker['FirstName']), $q) !== false || strpos
(strtolower($speaker['MiddleName']), $q) !== false || strpos(strtolower
($speaker['LastName']), $q) !== false) {
                $thespeaker = $speaker['Title']." ".$speaker['FirstName']." ".
$speaker['MiddleName']." ".$speaker['LastName'];
                $speakerlink = "?id=".$speaker['FacultyID'];
                echo '<a href="'.$speakerlink.'" title="'.$thespeaker.'">'.
$thespeaker.'</a>'."\n";

                //echo "{'text':'".$thespeaker."', 'url': '".$speakerlink."'},";
                }
}

The commented out portion is what I tried with JSON, though it's not
exactly correct due to an extra "," being printed out after the whole
thing is through. I've only used JSON one other time when I was
working with DojoToolkit on a project.

How would formatItem and formatResult work without using JSON? I
figured I could use the title attribute from the "a" tag, but item.attr
('title'), throws an error in formatItem.

Reply via email to