heh, sorry for the lack of response. here was the final code that worked great. I spent a good deal of time working on a autocomplete field used in conjunction with Mysql, and PHP. The insite is what i was thinking you for. 🙂
first just the final passing code from PHP to javascript.....
print ("<script>\n");
print ("var arrValues = [''");
for ($j=0; $j<$num_results; $j++)
{
$CustomerID = mysql_result($result,$j,"CustomerID");
$cust_fname = mysql_result($result,$j,"cust_fname");
$cust_lname = mysql_result($result,$j,"cust_lname");
$cust_mname = mysql_result($result,$j,"cust_mname");
$cust_info = "$cust_lname $cust_fname $cust_mname. $CustomerID";
print (",\"$cust_info\"");
}
print ("];\n");
print ("</script>\n");
and now the whole shabang.....autocomplete script and all......
<form method="post" action="/not_for_u/trans.php">
<font size = 5>Current Customer?</font><br><br>
<font size = 3>Select Customer:</font>
<html>
<head>
<title>Autocomplete Textbox Example</title>
<script type="text/javascript">
var isOpera = navigator.userAgent.indexOf("Opera") > -1;
var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera;
var isMoz = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !isOpera;
function textboxSelect (oTextbox, iStart, iEnd) {
switch(arguments.length) {
case 1:
oTextbox.select();
break;
case 2:
iEnd = oTextbox.value.length;
/* falls through */
case 3:
if (isIE) {
var oRange = oTextbox.createTextRange();
oRange.moveStart("character", iStart);
oRange.moveEnd("character", -oTextbox.value.length + iEnd);
oRange.select();
} else if (isMoz){
oTextbox.setSelectionRange(iStart, iEnd);
}
}
oTextbox.focus();
}
function textboxReplaceSelect (oTextbox, sText) {
if (isIE) {
var oRange = document.selection.createRange();
oRange.text = sText;
oRange.collapse(true);
oRange.select();
} else if (isMoz) {
var iStart = oTextbox.selectionStart;
oTextbox.value = oTextbox.value.substring(0, iStart) + sText + oTextbox.value.substring(oTextbox.selectionEnd, oTextbox.value.length);
oTextbox.setSelectionRange(iStart + sText.length, iStart + sText.length);
}
oTextbox.focus();
}
function autocompleteMatch (sText, arrValues) {
for (var i=0; i < arrValues.length; i++) {
if (arrValues.indexOf(sText) == sText.charAt(i)) {
return arrValues;
}
}
return null;
}
function autocomplete(oTextbox, oEvent, arrValues) {
switch (oEvent.keyCode) {
case 38: //up arrow
case 40: //down arrow
case 37: //left arrow
case 39: //right arrow
case 33: //page up
case 34: //page down
case 36: //home
case 35: //end
case 13: //enter
case 9: //tab
case 27: //esc
case 16: //shift
case 17: //ctrl
case 18: //alt
case 20: //caps lock
case 8: //backspace
case 46: //delete
return true;
break;
default:
textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode));
var iLen = oTextbox.value.length;
var sMatch = autocompleteMatch(oTextbox.value, arrValues);
if (sMatch != null) {
oTextbox.value = sMatch;
textboxSelect(oTextbox, iLen, oTextbox.value.length);
}
return false;
}
}
</script>
<?
include("config.inc");
$db = mysql_pconnect($hostname, $sqluser, $sqlpass);
print ("<script>\n");
print ("var arrValues = [''");
for ($j=0; $j<$num_results; $j++)
{
$CustomerID = mysql_result($result,$j,"CustomerID");
$cust_fname = mysql_result($result,$j,"cust_fname");
$cust_lname = mysql_result($result,$j,"cust_lname");
$cust_mname = mysql_result($result,$j,"cust_mname");
$cust_info = "$cust_lname $cust_fname $cust_mname. $CustomerID";
print (",\"$cust_info\"");
}
print ("];\n");
print ("</script>\n");
?>
</head>
<body>
Curent Client
<p>Type Name in Exact Case:<br />
<input name='cust_info' type="text" size='30' value="" id="txt1" onkeypress="return autocomplete(this, event, arrValues)" /></p>
</body>
</html>