Ajax Project - Form Entry Suggest
(vgl. http://www.crackajax.net/suggest.php)ajax.js
var url = "myajaxfunctions.php?param=";
function get_spot_id(idValue)
{
//var idValue = document.getElementById("agtel").value;
var myRandom = parseInt(Math.random()*99999999); // cache buster
http.open("GET", url + escape(idValue) + "&rand=" + myRandom, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function handleHttpResponse()
{
if (http.readyState == 4)
{
document.getElementById("hiddenDIV2").innerHTML=http.responseText;
document.getElementById("hiddenDIV2").style.width="200px";
//alert(document.getElementById("response_table_font").size);
var l = document.getElementById("response_table").rows.length;
document.getElementById("hiddenDIV2").style.height= l*25 +"px";
document.getElementById("hiddenDIV2").style.visibility="visible";
}
}
function loadrecord(record) {
//document.forms[1].telno.value = record;
document.getElementById("agtel").value = record;
document.getElementById("hiddenDIV2").innerHTML='';
document.getElementById("hiddenDIV2").style.height="0px";
document.getElementById("hiddenDIV2").style.width="0px";
document.getElementById("hiddenDIV2").style.visibility="hidden";
}
myajaxfunctions.php
if(strlen($_REQUEST['param'])>0){
/*$result = mysql_query("SELECT * FROM contact WHERE ContactTel LIKE '$_REQUEST['param']%'");
if(mysql_num_rows($result)>0)
{
while($myrow = mysql_fetch_array($result))
{
$agenttel = $myrow["ContactTel"];
$agentid = $myrow["ContactID"];
$textout .= "<table><tr style="border: 0px solid black"> <td style="border: 0px solid black; padding: 0px 10px 0px 10px"> <a href="javascript:loadrecord('".$agenttel."')">" .$agentid."</a></td> <td style="border: 0px solid black; padding: 0px 10px 0px 10px">" .$agenttel."</td></tr></table>";
}
}
else { $textout=""; }
*/
$textout .= "<table width='50px'>";
$textout .= "<tr style="border: 0px solid black"> <td style="border: 0px solid black; padding: 0px 10px 0px 10px"> <a href="javascript:loadrecord('112')">112</a></td> <td style="border: 0px solid black; padding: 0px 10px 0px 10px">Tom</td></tr>";
$textout .= "<tr style="border: 0px solid black"> <td style="border: 0px solid black; padding: 0px 10px 0px 10px"> <a href="javascript:loadrecord('100111')">100111</a></td> <td style="border: 0px solid black; padding: 0px 10px 0px 10px">Rainer</td></tr>";
$textout .= "</table>";
$textout='';
$textout .= "<font id='response_table_font' size='2'>";
$textout .= "<table id='response_table'>";
$textout .= "<tr > <td > <a href="javascript:loadrecord('112')">112</a></td> <td >Tom</td></tr>";
$textout .= "<tr > <td > <a href="javascript:loadrecord('112')">112</a></td> <td >Tom</td></tr>";
$textout .= "<tr > <td > <a href="javascript:loadrecord('112')">112</a></td> <td >Tom</td></tr>";
$textout .= "<tr > <td > <a href="javascript:loadrecord('112')">112</a></td> <td >Tom</td></tr>";
$textout .= "<tr > <td > <a href="javascript:loadrecord('112')">112</a></td> <td >Tom</td></tr>";
$textout .= "</table></font>";
}
echo $textout;
page.html
Wo?<br />
<input id="agtel" type="text" name="telno" onKeyUp="javascript:if(this.value.length > 3) get_spot_id(this.value);">
<div id="hiddenDIV2" name="hiddenDIV2" style="position:relative; top: 2px; left: 2px;width: 200px; visibility:hidden; background-color:white; border: 1px solid black;"> </div>