onChange in PHP Code not Working
Posted: Mon Dec 12, 2011 11:01 pm
Hi All,
In this time, I would like to share about My PHP code.
This PHP code function for when User input the Badge ID, then textbox_name and textbox_dept will show automatically from database.
But now I have a problem with this. When I want to input Badge ID, textbox_name and textbox_dept not show the details.
1. index.php
Appreciate with your helps
.
Thank you
In this time, I would like to share about My PHP code.
This PHP code function for when User input the Badge ID, then textbox_name and textbox_dept will show automatically from database.
But now I have a problem with this. When I want to input Badge ID, textbox_name and textbox_dept not show the details.
1. index.php
2. search.php<script>
function getXMLHTTP() {
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getCity(strURL) {
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('citydiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
<link rel="stylesheet" media="screen" href="style.css"/>
<html>
<head>
<title>Search the Database</title>
</head>
<body>
<form action="#" method="post" autocomplete="off">
<?php
echo
"
Badge ID <input type='text' name='badgeid' onChange='getCity('search.php?badgeid='+this.value)' maxlength='6' onkeyup='javascript:this.value=this.value.toUpperCase();'/><br/>
<div id='citydiv'>
Employee Name <input name='name' type='text' readonly><br>
Department <input type='text' readonly name='dept'>
</div>
"
?>
</form>
</body>
</html>
3. config.php<?php
ini_set( "display_errors", 0);
$badgeid=$_REQUEST['badgeid'];
mysql_connect ("localhost", "root","") or die (mysql_error());
mysql_select_db ("sei");
$sql = mysql_query("select * from employee where badgeid like '%$badgeid%'");
if ($row = mysql_fetch_array($sql)){
echo "Employee Name <input type='text' name='name' value='".$row['name']."'";
echo '<br/><br/>';
echo "Department <input type='text' name='dept' value='".$row['dept']."'";
echo '<br/><br/>';
}
else
{
echo "Employee Name <input type='text' readonly><br>";
echo "Department <input type='text' readonly>";
}
?>
* Before, It working properly if I make the code without PHP like below :<?php
$dbUser = "root";
$dbPass = "";
$dbName = "sei";
$dbHost = "localhost";
mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error());
mysql_select_db($dbName);
?>
Please help me to solve this problems.<form action="search.php" method="post" autocomplete="off">
Badge ID <input type="text" name="badgeid" onChange="getCity('search.php?badgeid='+this.value)" maxlength="6"/><br />
<div id="citydiv">
Employee Name
<input name="name" type="text" readonly><br>
Department
<input type="text" readonly name="dept">
</div></td>
</form>
Appreciate with your helps
Thank you

