I have a drop down box that a user selects their name and then I would like the rest of their details to be auto completed in the form.
I can talk to the ajax script and get the results from my database but I can’t fingure out how to auto complete the other input boxs in my form.
Any help would be great.
[CODE]
HTML
<select name=”autofill” id”txt1″ type”text” value=”<%=txtsearch%>” onChange=”showHint(this.value)”>
<%
strSQL = “SELECT * FROM tbl_phonelist ORDER By forename”
Set Rs = Server.CreateObject(“ADODB.Recordset”)
Rs.Open strSQL, Conn2, 1,3
do while not Rs.EOF
%>
<option value=”<%=Rs(“ID”)%>”><%=Rs(“forename”)%> <%=Rs(“Surname”)%></option>
<%
Rs.MoveNext
loop
%>
</select>
<p></p>
<input name=”firstname” type=”text” id=”firstname”>
<p></p>
<input name=”surname” type=”text” id=”surname”>
[CODE]
Ajax
var xmlHttp
function showHint(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=”ajax/hint.asp”;
url=url+”?q=”+str;
url=url+”&sid=”+Math.random();
//alert (str)
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;
}
[CODE]
Hint.asp
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”1252″%>
<!– #INCLUDE file=”../includes/conn.asp” –>
<%
Dim txtSearch
txtSearch = request.QueryString(“q”)
strSQL = “SELECT * FROM tbl_phonelist WHERE ID =” & txtSearch
Set Rs = Server.CreateObject(“ADODB.Recordset”)
Rs.Open strSQL, Conn2, 1,3
do while not Rs.EOF
%>
<%response.Write(Rs(“surname”))%>
<%
Rs.MoveNext
loop
%>