...

View Full Version : Need help getting result to display under textbox



emmals
05-16-2012, 03:11 PM
Hello ! I am trying to create an auto suggest drop down.

I have some ASP and Javascript code that I am using as an Autosuggest. Trouble is, the result displays on the main page, not under the text box like a drop down menu. I need help in getting the results to display correctly underneath the textbox. I have trawlled the internet and have loads and loads of code samples but I cant see the wood for the trees and I am really struggling with editing this code so that it displays correctly.



clienthint.asp



<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<html>
<head>
<script src="clienthint.js"></script>
</head>
<body>
<%
'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
%>
<form name="form1" action="clienthint.asp" method="post">
Enter Word:
<input type="text" name="txt1" id="txt1" onKeyUp="showHint(this.value,'txt1','form1',true)">
<input type="submit" name="submit" value="submit">
</form>
<p>Suggestions: <span id="txtHint"></span></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=SQLOLEDB; Data Source=JAGUAR\SQLEXPRESS; Initial Catalog=67625252; User ID=SFSDFSDF; Password=KJHSDHFJHDF"
rsWords.Source = "SELECT * FROM Rmatable WHERE (RMA_ID LIKE'" + q + "%') ORDER BY RMA_ID"
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("RMA_ID") & "','" & b & "','" & f & "','" & a & "');"">" & rsWords("RMA_ID") & "</a>"
Else
hint = hint & " , <a href=""javascript:setTextBox('" & rsWords("RMA_ID") & "','" & b & "','" & f & "','" & a & "');"">" & rsWords("RMA_ID") & "</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
%>

emmals
05-17-2012, 01:11 PM
anyone ?

Philip M
05-17-2012, 03:45 PM
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;

Assuming that you do have an element (p, span or div) with the id of "txtHint" then that code ought to display the response text in that element.


It is your responsibility to die() if necessary….. - PHP Manual



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum