Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Need help getting result to display under textbox

    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

    Code:
    <%@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

    Code:
    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

    Code:
    <%@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
    %>

  • #2
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anyone ?

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    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

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •