Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8513989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:44:15+00:00 2026-06-11T04:44:15+00:00

I’ve found a number of examples that show how to highlight multiple matches e.g.

  • 0

I’ve found a number of examples that show how to highlight multiple matches e.g. if i type in “art design”, I would want it to highlight it as “art and design degree”

The following example (albeit with a static array) is what I’m after:
http://jsfiddle.net/Q4jy9/1/

However, I don’t know how to get this working for a remote php datasource.
Below is the current code I’m using. Each keypress sends the term to my php and that selects matches from the database.

Is there a way I can either change the script below to allow highlighting of multiple words/matches, or change the script in the above link to work with an external datasource?

var termTemplate = "<span class='ui-autocomplete-term'>%s</span>";
$("#f input").autocomplete({
   source: "livesearch.php",
   open: function(e, ui) {
      var origKeyword = $("#f input").val();
      var acData = $(this).data('autocomplete');
      acData.menu.element.find('a').each(function() {
         var me = $(this);
         var regex = new RegExp(acData.term, "gi");
         me.html(me.text().replace(regex, function(matched) {
            return termTemplate.replace('%s', matched);
         }));
      });

   },
   select: function(event, ui) {
      var keyword = $("#f input").val();
      $("#f input").val('');
      window.location.href = 'MYURLHERE?VARIABLE=' + ui.item.value;
      return false;
   },
   focus: function(event, ui) {
      return false;
   }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:44:17+00:00Added an answer on June 11, 2026 at 4:44 am

    With the help of tborychowski, I think we have a working solution 🙂

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.2.js'></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.js"></script>
    
    <style type='text/css'>
       .srchHilite {background-color: yellow;}
    </style>
    
    <script type='text/javascript'>
    $(document).ready(function(){
    
    var termTemplate = "<span class='ui-autocomplete-term'>%s</span>";
    $("#tags").autocomplete({
     source: function(request, response) {
            $.getJSON("livesearch.php", request, function(data, status, xhr ) {
    
                var newmatchArry = new Array();
                var matchArry   = data.slice ();
                var srchTerms   = $.trim (request.term).split (/\s+/);
    
                    //--- For each search term, remove non-matches.
                    $.each (srchTerms, function (J, term) {
                        var regX    = new RegExp (term.value, "i");
                        matchArry   = $.map (matchArry, function (item) {
                            return regX.test (item)  ?  item  : null;
                        } );
                    } );
    
                response(matchArry);
    
            });
        },
    
      open:   function (event, ui) {
                    /*--- This function provides no hooks to the results list, so we have to trust the
                        selector, for now.
                    */
                    var resultsList = $("ul.ui-autocomplete > li.ui-menu-item > a");
                    var srchTerm    = $.trim ( $("#tags").val () ).split (/\s+/).join ('|');
    
                    //--- Loop through the results list and highlight the terms.
                    resultsList.each ( function () {
                        var jThis   = $(this);
                        var regX    = new RegExp ('(' + srchTerm + ')', "ig");
                        var oldTxt  = jThis.text ();
    
                        jThis.html (oldTxt.replace (regX, '<span class="srchHilite">$1</span>') );
                    } );
                }
    } );
    
    });
    </script>
    </head>
    
    <body>
    <input id="tags">
    
    </div>
    </body>
    
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.