Adsense

Ajax form suggestion

schform.php


<html>
<head>
<script type="text/javascript">

var url = "getagenttel.php?param=";
function getagenttel()
{
var idValue = document.getElementById("agtel").value;

var myRandom = parseInt(Math.random()*99999999); // cache buster

if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();

}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function()

{
if(xmlhttp.readyState==4 && xmlhttp.status==200)

{
document.getElementById("hiddenDIV2").style.visibility="visible";

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

}
}

xmlhttp.open("GET", url + escape(idValue) + "&rand=" + myRandom,true);
xmlhttp.send();
}

function loadrecord(record) { document.schform.telno.value = record; }
</script>
</head>
<body>
<form name="schform" onReset="this.telno.value='';getagenttel()">
<table>
<tr>
<td>Tel Number:</td>
<td><input id="agtel" type="text" name="telno" onKeyUp="getagenttel();">
  <input type="reset" value="Clear Entry Field"></td></tr>
</table>
</form>
<div id="hiddenDIV2" style="position:relative; top: -22px; left: 85px;width: 200; visibility:hidden; background-color:white; border: 1px solid black;"> </div>

</body>
</html>




getagenttel.php


<?php

$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="suggest"; // Database name
$con = mysql_connect("$host","$username","$password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("$db_name", $con);

//mysql_close($con);

if(strlen($param)>0)
{
$result = mysql_query("SELECT * FROM contact WHERE ContactTel LIKE '$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=""; }
}
echo $textout;

?>


database: suggest

-- Table structure for table `contact`
--

CREATE TABLE `contact` (
  `ContactTel` double NOT NULL auto_increment,
  `ContactID` varchar(50) NOT NULL,
  PRIMARY KEY  (`ContactTel`),
  UNIQUE KEY `ContactTel` (`ContactTel`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1778 ;

--
-- Dumping data for table `contact`
--

INSERT INTO `contact` (`ContactTel`, `ContactID`) VALUES
(1122, 'ATTORNEY'),
(1223, 'FAYE'),
(1234, 'ANNE'),
(1777, 'BOSS');

1 comment:

comment here

newest questions on wordpress