I am making a fullname text field and want it so that when people start to type, it accesses the users table in the database and suggests names, the user clicks one to autocomplete the text field. This will hopefully prevent fullname spelling errors. I got this working no problem, but, is it possible to populate another text field automatically.
Here is the code I have to make it populate the fullname text field, but I need the employee number info to go into the employee number text field and not into the fullname space.
Can anyone help?
Thanks
Here is the code I have to make it populate the fullname text field, but I need the employee number info to go into the employee number text field and not into the fullname space.
Code:
//form page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<title>Autocomplete</title>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<script type="text/javascript">
$().ready(function() {
$("#fullname").autocomplete("script.php", {
width: 500,
matchContains: true,
selectFirst: false
});
});
</script>
</head>
<body>
<div id="content">
<form autocomplete="off" method='get'>
<p>
Enter Name <label>:</label>
<input type="text" name="fullname" id="fullname" />
<input type="text" name="employeenumber" id="employeenumber" />
</p>
<input type="submit" value="Submit" />
</form>
</div>
</body>
</html>
Code:
//script page
<?php
$host="###";
$username="###";
$password="###";
$db_name="###";
$con = mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db_name, $con) or die(mysql_error());
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = "select fullname, employeenumber from users where fullname LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$fullname = $rs['fullname'];
$employeenumber = $rs['employeenumber'];
echo "$fullname, $employeenumber\n";
}
?>
Can anyone help?
Thanks