473,414 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to use jQuery's formatItem with autocomplete?

Hello,

I am trying to format the output of my data with the autocomplete function from jQuery. So far, I've been able to build the entire process, however, I want to limit the information I show in the autocomplete, but I still want the autocomplete to search through the entire string to find possible matches.

I understand that the formatItem function used in conjunction with the autocomplete from jQuery can accomplish this.

To give you some background here is the entire sequence of my code:
Expand|Select|Wrap|Line Numbers
  1.  $sql = ( 'SELECT cr, title, author, content, id FROM da_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->cr . ": " . $row->title . ": " . $row->content,
  8.                          );
  9.       }
  10.  
The above is the php I use to select the data for the autocomplete to look up. The problem is that the data associated with 'content' is enormously large and I would prefer that it did not show in the autocomplete suggestions, but I still would like the autocomplete to look at it in order to come up with a suggestion.

Expand|Select|Wrap|Line Numbers
  1. <script>
  2.       var AllCRData = <?= json_encode ( $Response ); ?>;
  3.       var CRs = [];
  4.  
  5.       for(var i in AllCRData){
  6.          CRs.push(AllCRData[i].name);
  7.       }
  8.  
  9.       function getIdFromCR(_name){
  10.           for(var i in AllCRData){
  11.               if(_name == AllCRData[i].name){
  12.                   return AllCRData[i].id;
  13.               }
  14.           }
  15.       }
  16.  
  17.   $(document).ready(function(){
  18.          $("#Responses").autocomplete({
  19.              source: CRs,
  20.               select: function(e, ui){
  21.                  $("#hidden_cr").val( getIdFromCR($("#Responses").val()) );
  22.               }});
  23.      });
  24. </script>
  25.  
The above is the javascript I'm using to populate the autocomplete. I believe that the formatItem function would appear somewhere in the final portion of the javascript, but I am not sure how to implement it for my purposes.

I would like to format my autocomplete, so that it only shows $row->cr and $row->title from the php above, while hiding the $row->content, yet, still searching through the 'content' in order to find the most appropriate option.

I would really appreciate your assistance on how to implement the formatItem function for the autocomplete for jQuery.

Thanks!
Nov 17 '10 #1
0 1880

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

Similar topics

1
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...
6
by: rakesh19 | last post by:
Hi, I am building an application similar to google autosuggest. I want to fetch the list of items to be suggested using PHP. Those items are stored in a database. Is it a good idea to make a...
1
blyxx86
by: blyxx86 | last post by:
Hey everyone, I'm fairly new to javascript. I hardly ever use it, but my newest project is demanding that I have 'dynamic' drop downs where the user can type in their partial matches. So, I...
2
blyxx86
by: blyxx86 | last post by:
Hello Everyone! I'm starting to realize the project I'm working on is going to have a high demand for AJAX type integration. Most notably with the forms that need to be filled out by the user. ...
0
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
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...
7
by: Sirajuddin | last post by:
Hi, With great hope im writing this email. I wish and hope someone can help me. Im trying to get code for Autocomplete Textbox. I mean im looking for textbox which will autocomplete textbox...
4
by: ghopz | last post by:
I have my code didn't work properly, if I add additional condition on where clause like AND ServiceID = '$searchServiceID' the form didn't display. here are my codes. Please help..Thanks this is...
2
by: rhtdmrai | last post by:
suppose i have gridview in which i have multiple empty Textbox ; In this i want to use autocomplete property of jquery in a particular textbox ; so fro this i have to firstget the id of this textbox...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.