We help IT Professionals succeed at work.
Get Started

CFC Lookup - When Not Found

digitalwise asked
Last Modified: 2015-12-16
We have a CFC that we are using to look up a school - I want to limit it so they can't enter something that isn't in the lookup.

Form fields

input type="text" class="form-control" id="schoolname" name="schoolname" value="#getapp.showipeds#" />
    <input type="hidden" class="form-control" name="AI_IPEDS" id="AI_IPEDS" value="#getapp.AI_IPEDS#" />

Open in new window


            source: function(request, response){
                    url: "ipeds.cfc?method=companyNameList",
                    dataType: "json",
                    data: {
                        searchterm: request.term
                    success: function(data){
            minLength: 3,
            select: function(event, ui) {

Open in new window


<cffunction name="companyNameList" access="remote" output="false" hint="I return a list of companies with IDs" returnformat="JSON">
    <cfargument name="searchterm" required="false" default="" />

      <cfset var returnArray = arrayNew(1) />
<cfquery name="qryStates" dataSource="mcsf">
    Select schoolname + ' (' + schoolcity + ', ' + schoolstate + ')' as showme, ipedsid from College_IPEDS where schoolname like <cfqueryparam value="%#arguments.searchterm#%" cfsqltype="cf_sql_varchar"> order by schoolname, schoolstate
 <CFIF qryStates.recordcount>
<cfloop query="qryStates">
    <cfset statesStruct = StructNew() />
    <cfset statesStruct["id"] = ipedsid />
    <cfset statesStruct["label"] = showme />
    <cfset ArrayAppend(returnArray,statesStruct) />
<cfset statesStruct = StructNew() />
    <cfset statesStruct["id"] = 0 />
    <cfset statesStruct["label"] = showme />
    <cfset ArrayAppend(returnArray,statesStruct) />
<cfreturn returnArray />

Open in new window

Watch Question
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE