Results 1 to 1 of 1

Thread: JQuery Autocomplete - multiple terms?

Threaded View

  1. #1
    Join Date
    Apr 2011
    Accelerating Windows at 9.81 m/s....

    JQuery Autocomplete - multiple terms?

    DanInMA suggested I start a new thread

    I've got a fine looking search box with a JQuery autocomplete that looks impressive at first glance.

    I'm trying to make it work for multiple terms --- "foobar" works fine, but the script stops matching and suggesting (in the browser) after a space, so "foobar baz" won't be matched. Watching in Firebug, I see the serviceURL is still providing matching data, so I'm pretty sure the problem is located somewhere on the Javascript side. I've spent more time than I should reading similar threads in places like StackOverflow and have a thread over at PHPBuilder as well, but the last advice there was that I should use PHP's json_encode() ... and that's not the point ... AAMOF it's not been working with json_encode.

    Anyway, here's the stuff:

    In the HTML header of the search page:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="includes/jquery.autocomplete.js"></script>
    I've attached the latter *js file.

    In the page itself:
    <script type="text/javascript">
        var a = $('#searchbox').autocomplete({
        multiple: true,
        multipleSeparator: " ",
        delimiter: /(,|;)\s*/, // regex or character
        zIndex: 9999,
        deferRequestBy: 0, //miliseconds
        noCache: false //default is false, set to true to disable caching
        //callback function:
        // local autosugest options:
        //local lookup values
    Here's Autocomplete.php:
    PHP Code:

    // autocomplete.php --- feeds suggestions to
    // the AJAX autocomplete (Java)script on our searchbox.

    /* According to the docs for the JQuery plugin, we must
       echo the output EXACTLY as shown (a modified JSON).
       Third list ("data") is optional.
     suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'],

    // connect to the DB
    include "includes/functions/db.func.php";
    if (!
    $connect) die("DB connection failed");

    $_GET['query']) && $_GET['query'] != '') {
    $dbquery="select title from our_table where live=1 and title like '%$qr%' limit 15";
    $result mysql_query($dbquery);
       if (!
    $result) exit;
    $replacer=array("\n","\r\n","<br>","<br />","<BR>");
       while (
    $row mysql_fetch_row($result)) {
    $jsonout[] = str_replace($replacer," ",urldecode($row[0]));
    // return the array as json with PHP
    echo "{
       foreach (
    $jsonout as $jj) {
          if (
    $counter<$count) {
    // logging routine omitted
    Thanks very much, in advance, for any hints or clue-stick clobbers.
    Attached Files Attached Files
    Last edited by dalecosp; 05-09-2012 at 10:50 AM.
    "God doesn't play dice." --- Albert Einstein
    "Perl is hardly a paragon of beautiful syntax." --- Weedpacket, on PHPBuilder

    Getting Help at All! --- PHP Debugging 101 --- Search the board before posting a new thread --- R.T.F.M. (the 'friendly' {PHP!!!} manual, in English) --- OMBE: Office Machines, Business Equipment

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles