473,657 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use jQuery's formatItem, formatMatch, & formatResult options for autocomplete?

75 New Member
Hello,

I am making use of jQuery's .autocomplete plugin, and I would appreciate some assistance formating the results that show up in the dropdown menu that populates when text is written into the input field.

In order to get the data to populate the autocomplete, I pull from mySQL using this PHP:
Expand|Select|Wrap|Line Numbers
  1.  $sql = ( 'SELECT tag, title, author, content, id FROM labels' );
  2.  $result = mysql_query( $sql );
  3.  $Response = array();
  4.  while( $row = mysql_fetch_object( $result ) ){
  5.  $Response[] = array(
  6.                            "id" => $row->id,
  7.                            "name" => $row->tag . ": " . $row->title . ": " . $row->content .""
  8.                          );
  9.  }
  10.  
When a user selects the option from the autocomplete that is best for them, I convert the "name" above into the "id" using this method:
Expand|Select|Wrap|Line Numbers
  1.   var AllTagData = <?= json_encode ( $Response ); ?>;
  2.   var CRs = [];
  3.  
  4.   for(var i in AllTagData){
  5.      Tags.push(AllTagData[i].name);
  6.   }
  7.  
  8.   function getIdFromTag(_name){
  9.       for(var i in AllTagData){
  10.           if(_name == AllTagData[i].name){
  11.               return AllTagData[i].id;
  12.           }
  13.       }
  14.   }
  15.  
So far, so good. Finally, I use the jQuery autocomplete plugin to output the data for the user:
Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function(){
  2.      $("#Responses").autocomplete({
  3.          source: Tags,
  4.          matchContains: true,
  5.          autoFill: true,
  6.          select: function(e, ui){
  7.              $("#hidden_tags").val( getIdFromTags($("#Responses").val()) );
  8.           }});
  9.  });
  10.  
This final portion of the code is where I need help implementing the formatItem, formatMatch, and formatResult options.

From the PHP given above, I output Tags, Title, and Content all in the "name". The way that I would like to format my autocomplete options for the user is
  • Show Tags & Title
  • Hide Content
  • Search through Tags, Title, and Content for possible matches
Therefore, even though I want the autocomplete to search through Content, I don't want Content showing up in the populated autocomplete list. I only want the Tags and Title to show.

I've been having a lot of trouble with this and have searched quite extensively to find an answer and would really appreciate any help you can give on how to accomplish this. Please ask any follow up questions if you need further clarification. Thanks!
Nov 20 '10 #1
0 2085

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1845
by: c19h28o2 | last post by:
Hi, I'm a little stuck with Ajax (really am not getting it at the moment!) I'm trying to write into a div when something is typed into a box... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head>
1
49872
by: mikeh3275 | last post by:
I'm new to developing in jQuery, so I'm probably doing this wrong. I'm loading a form into a modal dialog box and I'm trying to assign a click event to the button in the form, but I can't seem to get anything to happen. Below is the code. Thanks in advance. jQuery: jQuery(document).ready(function() { jQuery("a").click(function() { jQuery("#dialog").dialog({ modal: true,
53
8370
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script language="javascript" type="text/javascript">
0
3344
by: metaphysics | last post by:
I am using a jQuery script called LocalScroll, and I have a quick problem that needs fixing. The demo for the script is here: jQuery.LocalScroll - Regular Demo, and the documentation is here: Ariel Flesler: jQuery.LocalScroll. The Local Scroll script uses the toScroll and jQuery scripts to function. I don't really understand what "hash" means, however the author in the documentation specified that if hash is set to true, the hash of the...
5
4933
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
2301
by: bytesFTW99 | last post by:
i have this, $(function() { $('#input').autocomplete('test.php', {json: true}); }); that bring back values from the database here is my php section
2
2834
pradeepjain
by: pradeepjain | last post by:
http://www.electrictoolbox.com/jquery-count-words-textarea-input/ hi guys i want to build a autocomplete feature in a textarea . so i thought of like when ever the word count increases call the ajax/jquery so as to find the autocomplete from server . i am using the word count feature from above url . how do i pass the present entered word to server for checking .bcos there may be multiple words also . like hello BP .. when BP is typed...
2
6033
by: RichRadio | last post by:
Hi, I have the following script within a user control <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script type="text/javascript"> jQuery().ready(function() {
0
2763
by: aucontraire | last post by:
I'm using a swf as a background for all of the content on a site. Every page has the same background (swf) but with different amount of content. I want to sync the height of the div of the content with the div of the swf so that the swf nicely frames the content. I have been able to find pieces of this overwhelming puzzle but have been quite unsuccessful at putting them together. I'm a complete novice when it comes to javascript and...
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.