Copy link to clipboard
Copied
I've added an AutoSuggest script to my site that offers suggestions as the user types their search keyword(s). The script works great except that it performs a search with every keystroke. I have spent the past 3 days trying out different jquery scripts that will for when a user stops typing before sending the search request, but I cannot get any of them to work correctly. Some prevent the search from being sent until the user clicks OUT of the search box, but I need a script that will work when the user stops typing for (xxx ms). I have include my code below in hopes someone might be able to help.
BTW: I do not know jquery or javascript much at all. I can often look at a script and know what to edit, but that's about it. Even this script for the AUTOSUGGEST was from a post I found online.
CSS
------------------------------------------------------------
<style type="text/css">
div.autosuggest{position:absolute;float:left;width:460px;margin-left:-200px;}
input.autosuggestinput{ z-index:1000000;}
div.autosuggestcontainer {position:relative;top:.3em;width:100%;background-color:#FFFFFF;font-size:11px;font-family:Arial, Helvetica, sans-serif}
</style>
------------------------------------------------------------
FORM
------------------------------------------------------------
<cfform mehod="post" enctype="multipart/form-data" action="searchresult.cfm" style="margin:0px;">
<input type="text" name="search" autocomplete="off" id="out">
</cfform>
------------------------------------------------------------
CFDIV
--------------------------------------------------------
<div id="criteriaautosuggest" class="autosuggest">
<div id="criteriacontainer" class="autosuggestcontainer">
<cfdiv bind="url:#request.app.storepath#/include/search/getresults.cfm?search={search@keyup}" bindOnLoad = "true" style="background-color:##D2E8E8"/>
</div>
</div>
GETRESULTS.CFM
--------------------------------------------------------
<cfset url.search = left(url.search,100)>
<cfset url.search = rereplacenocase(url.search,"[()]","","all")>
<cfif #len(trim(url.search))# is "0"><cfset url.search = "xyz0123"></cfif>
<CFSEARCH
Name="getresults2"
Collection="store"
Type="simple"
CRITERIA="#ucase(url.search)#"
Maxrows="15">
<CFOUTPUT QUERY="getresults2">
<div style="padding:4px; border:1px solid black;">
<a href="#path#/detail.cfm?pid=#key#">#title#</a>
</div>
</CFOUTPUT>
I am hoping someone has a simple script that will allow a delay before the search request is sent to the GETRESULTS.CFM page and returned into the CFDIV.
Thank you,
Ron
Have something to add?