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 6705323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:23:26+00:00 2026-05-26T07:23:26+00:00

I’m stumped. I have an existing autocomplete function which worked when called from a

  • 0

I’m stumped. I have an existing autocomplete function which worked when called from a ColdFusion autosuggest input. Now, I’m trying to convert the page to use a jQuery autocomplete input, and can’t make it work. Here’s the existing function, in autosuggest.cfc:

<cffunction name="lookupSerialNumber" access="remote" returntype="Array" >
    <cfargument name="search" type="any" required="false" default="">

    <!--- Define variables --->
    <cfset var data="">
    <cfset var result=ArrayNew(1)>

    <!--- Do search --->
    <cfquery name="data">
        SELECT DISTINCT SERIAL_NUMBER
        FROM myTable
        WHERE SERIAL_NUMBER LIKE '%#trim(ARGUMENTS.search)#%'
        ORDER BY SERIAL_NUMBER
    </cfquery>

    <!--- Build result array --->
    <cfloop query="data">
        <cfset ArrayAppend(result, list)>
    </cfloop>

    <!--- And return it --->
    <cfreturn result />
</cffunction>

When I call it from my autocomplete input after entering “01”, the Console shows a response like this:

   ["0000003001","0100002000","0100002001","0100002002","0100002003","0100002004",7300000100,7300000101,7300000102,7300000103,7300000104,7300000105,7300000107,7300000108,7300000109,7300000110,7300000111,7300000112]

Note that the first six responses are inside double quotes, while the rest are not. The autocomplete shows the first six responses, but not the rest.

So that’s my first problem. The second is that I want the response to be injected into both the text and the value of the input; currently, only the text shows the response. I’m not surprised, as I’m only returning a single value. However, I can’t figure out how to accomplish this.

I’ve tried initializing the autocomplete with a parse function, like so:

$(document).ready(function(){
        $('#myInputID').autocomplete(
            {source: function(request, response) {
                $.ajax({
                    url: "cfc/autoSuggest.cfc?method=lookupSerialNumber>&returnformat=json",
                    dataType: "json",
                    data: {
                      search: request.term,
                      maxRows: 10
                    },
                    success: function(data) {
                      response(data);
                    }                   
                })
            },
            parse: function(data){
                return $.map(data, function(item) {
                    return { data: item, value: item, result: item };
                });
            }
        });
    });

but this accomplishes nothing. Since the parse function isn’t in the autocomplete API, I’m flying blind here.

I figured that these problems were related enough to not split them out into two questions; let me know if you think I should. As always, thanks.

  • 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-05-26T07:23:27+00:00Added an answer on May 26, 2026 at 7:23 am

    Put your query results in a structure and add that to an array. Then convert to json. The autocomplete is expecting json back and either a label or a value field or both. Here is an example:

    <cffunction name="lookupSerialNumber" access="remote" returntype="String" >
        <cfargument name="search" type="any" default="">
    
        <!--- Define variables --->
        <cfset var data="">
        <cfset var result=ArrayNew(1)>
        <cfset var returnStruct = "">
    
    
        <!--- Do search --->
        <cfquery name="data">
            SELECT DISTINCT SERIAL_NUMBER
            FROM myTable
            WHERE SERIAL_NUMBER LIKE <cfqueryparam value="%#trim(ARGUMENTS.search)#%" 
                                         cfsqltype="cf_sql_varchar">
    
            ORDER BY SERIAL_NUMBER
        </cfquery>
    
        <!--- Build result array --->
        <cfloop query="data">
            <cfset returnStruct = StructNew() />
            <cfset returnStruct["label"] = SERIAL_NUMBER />
    
            <cfset ArrayAppend(result,returnStruct) />
        </cfloop>
    
        <!--- And return it --->
        <cfreturn serializeJSON(result) />
     </cffunction>
    

    You can use the serializeJSON function if it’s available in whatever version of CF you are using. If not, build the json string by hand.

    Here is a tut: http://www.jensbits.com/2010/03/18/jquery-ui-autocomplete-with-coldfusion/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.