We help IT Professionals succeed at work.
Get Started

how do get a drop down values filled as I am typing

goodk
goodk asked
on
397 Views
Last Modified: 2012-05-12
ok, the ajax code is working and I do get the returned value in

  document.getElementById("txtHint").innerHTML = xmlhttp.responseText;

but I really want the value to change in the field I am typing the value or the field becomes a dropdown as I am typing.  


<input type="text" name="txtn1" id="txt1" .....................


CODE:
<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
<script type="text/javascript">
    function showHint(str)
{
var xmlhttp;
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
       document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
   
    }
  }
xmlhttp.open("GET","ajaxresponse.aspx?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<h3>Start typing a name in the input field below:</h3>
<form id="form1" action=""> 
First name: <input type="text" name="txtn1" id="txt1" onkeyup="showHint(this.value)" />

<p>Suggestions: <span id="txtHint"></span></p> 
</form>



server file CODE

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
      <title></title>
 
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    <%
Response.Expires=-1;
string[] a = new string[30];

//Fill up array with names
a[1]="Anna";
a[2]="Brittany";
a[3]="Cinderella";



//get the q parameter from URL
string q=Request.QueryString["q"];
q=q.ToUpper();
  string hint="";

//lookup all hints from array if length of q>0
if (q.Length>0)
{
  for (int i=1;i<30;i++)
  {/*
    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
    */
    }
    }
    hint=a[1];
//'Output "no suggestion" if no hint were found
//'or output the correct values
    if (hint == "")
        Response.Write("no suggestion");
    else
        Response.Write(hint);
  
%>
   
    
    </div>
    </form>
</body>
</html>

Open in new window

Comment
Watch Question
Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE