Jump to content

Ajax search box assistance please


crlaurence

Recommended Posts

I put together a search box that uses one of the simple suggest (like google suggest) and w3 schools suggest, but cannot figure out how to do the following1) What part of the code tells it where to look in the search string? If you dont want to limitthe typed in search request to the 1st characters of the results table, and you want it to searchfor the text anywhere in a Title.2) What parameter do you change to have it start looking after say the 2nd typed in letter insteadof the 1st?3) As the results begin to appear, if you typed in say "tool", how could the word tool be shaded adifferent color wherever it appears on each result?4) How can you display the information as part of the search box instead of in its own table?Thank you so very much for any assistance you can provide.============var xmlHttpfunction showaz(str){if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; }xmlHttp=GetXmlHttpObject()if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; }var url="showaz2.asp";url=url+"?q="+str;url=url+"&sid="+Math.random();xmlHttp.onreadystatechange=stateChanged;xmlHttp.open("GET",url,true);xmlHttp.send(null);}function stateChanged(){if (xmlHttp.readyState==4){document.getElementById("txtHint").innerHTML=xmlHttp.responseText;}}function GetXmlHttpObject(){var xmlHttp=null;try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }return xmlHttp;}

Link to comment
Share on other sites

The magic is in the gethint.asp. You can do what you want in the gethint.asp (in the tutorial, in you case, should be "showaz2.asp") by modifing this part:<code>'lookup all hints from array if length of q>0if len(q)>0 then hint="" for i=1 to 30 if q=ucase(mid(a(i),1,len(q))) then if hint="" then hint=a(i) else hint=hint & " , " & a(i) end if end if nextend if</code>good luck.

Link to comment
Share on other sites

Thank you for your reply.I see this in the w3schools version which I modified to query an sql database, not to use an array on the same page.Any suggestions on changing the below to use this information?sql="SELECT distinct top 20 title, catalogid FROM title INNER JOIN header on id = id where catalogid = '3' and title.a_Title like "sql=sql & "'%" & replace(replace(request.querystring("q"), "'", "''"), "%", "" ) & "%'"

The magic is in the gethint.asp. You can do what you want in the gethint.asp (in the tutorial, in you case, should be "showaz2.asp") by modifing this part:<code>'lookup all hints from array if length of q>0if len(q)>0 then hint="" for i=1 to 30 if q=ucase(mid(a(i),1,len(q))) then if hint="" then hint=a(i) else hint=hint & " , " & a(i) end if end if nextend if</code>good luck.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...