Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Bad Boy

Auto Sugestão

Recommended Posts

Seguinte galera encontrei esse script na internet de auto sugestão e eu queria transforma-lo em algo no estilo do google ao inves de aparecer em forma de texto aparece-se como a do google abaixo tem o codigo, se poderem me ajudar agradeço!

 

clienthint.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<html>
<head>
<script language="javascript" type="text/javascript" src="AutoComplete.js"></script>
<script src="clienthint.js"></script> 
</head>
<body>
<font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
<%
'this displays the value of the textbox after the form is submitted
If trim(Request("txt1")) <> "" Then
	Response.Write "You entered:"
	Response.Write "<b>" & Request("txt1") & "</b><br /><br />"
End If
%>
</font><font face="Verdana, Arial, Helvetica, sans-serif">
<form name="form1" action="clienthint.asp" method="post">
  <font size="2"> Pesquisar: 
  <input name="txt1" type="text" id="txt1" onKeyUp="showHint(this.value,'txt1','form1',true)" size="60">
  <input type="submit" name="submit" value="Pesquisar">
  </font>
</form>
</font> 
<p><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Sugestão 
  para a pesquisa: <span id="txtHint"></span></font></p> 
</body>
</html>

clienthint.js

var xmlHttp

function showHint(str, box, thisForm, autoSubmit)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="gethint.asp";
url=url+"?q="+str;
url=url+"&b="+box;
url=url+"&f="+thisForm;
url=url+"&a="+autoSubmit;
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;
}

//this function allows for Clickable suggestions
function setTextBox(thisText,thisBox,thisForm,autoSubmit){
	document.getElementById(thisBox).value = thisText
	//this autoSubmits the form after a suggestion is clicked - it is not working :(
	//if(autoSubmit=='true'){
	//	alert(thisForm);
	//	document.getElementById(thisForm).submit();
	//}
}

gethint.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
response.expires=-1
Dim rsWords
Dim rsWords_numRows
Dim q
Dim b
Dim hint
q=ucase(request.querystring("q"))
b=(request.querystring("b"))
f=(request.querystring("f"))
a=(request.querystring("a"))
hint=""
Set rsWords = Server.CreateObject("ADODB.Recordset")
rsWords.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db_hint_words.mdb")
rsWords.Source = "SELECT TOP 10 word FROM TBL_WORDS  WHERE (word LIKE'" + q + "%') ORDER BY WORD"
rsWords.CursorType = 2
rsWords.CursorLocation = 2
rsWords.LockType = 3
rsWords.Open()
rsWords_numRows = 0

If Not rsWords.EOF Then
	Do While Not rsWords.EOF
		If trim(hint) = "" Then
			hint = "<a href=""javascript:setTextBox('" & rsWords("word") & "','" & b & "','" & f & "','" & a & "');"">" & rsWords("word") & "</a>"
		Else
			hint = hint & " , <a href=""javascript:setTextBox('" & rsWords("word") & "','" & b & "','" & f & "','" & a & "');"">" & rsWords("word") & "</a>"
		End If
		rsWords.MoveNext()
	Loop
End If
if trim(hint)="" then 
  response.write("no suggestion")
else
  response.write(hint)
end if

rsWords.Close()
Set rsWords = Nothing
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.