Great tool, but I'm only ever able to show one option from my array in my list. I have an array containing over 20k items, pulled from a db and know that there should be more than one sometimes.
My solution probably won't help you, but might point in the right direction.
I use PHP/MySQL/Smarty (templating system). I do my query and build an array (in my case, 22000 publisher names), and then pass the array to the template. All javascript in the template must be 'controlled' so that the template engine does not try and interpret it, but just let it through. This is done by adding {literal} before and {/literal} after the js code. by placing '{/literal}{$pub_array}{literal}' into the array part of the js code, I can populate the array with my MySQL output.
The problem that I have is that I can only see one autocomplete option being offered when I know there are more that one in my test sample.
I Figured Out :
this is the Code you need to Replace :
REPLACE THIS LINE in (autocomplete.htm) file:
var customarray=new Array('an apple','alligator','elephant','pear','kingbird','kingbolt', 'kingcraft','kingcup','kingdom','kingfisher','kingpin');
WITH THIS PHP CODE:
<?php
///// THIS IS YOUR DATA BASE CONNECTION/////////////////////////////////////
function db_connect()
{
$db = mysql_connect("localhost","YOUR USER","YOUR PASSWORD");
if (!$db)
{
echo "Error ";
exit;
}
mysql_select_db("YOUR DATABASE");
}
db_connect();
//////////////////////////////////////////////////////////////////////////////////////////////
//////////THIS LINE POPULATE YOUR ARRAY FROM A MYSQL QUERY///////////////////
$result = mysql_query("SELECT your_column FROM your_table ORDER BY your_column");
if (mysql_num_rows($result))
{
while ($row = mysql_fetch_assoc($result))
{
$customarray[] = $row[your_column];
}
}
hi i m reteriving data from sql server
e.g
i have fetched brand name and brand code from sql server table. i have created array of brandname now when user select any brand in the list then brand code should comes into next textbox automatically
Hi does any body know how to change the font color from black to white when moving over the list....I have customized the code and applied the hcolor to purple so now the characters in side cannot be seen...so when i move over the options the color of the character should change to white for visibility...if any one has idea plz reply ....its very very urgent....
You helped me my job........ i am trying this code from past 4 days. i thought to try in google once. unexpectedly i saw your code and i have tried it's working excellent....
i request you one more thing is i want the same futhure's of the another textbox which present in the same page.... can you suggest me...
Hi,
suppose there is elephant in custom aray and user types elepha then why do after pressing enter elephant get selected .
Rather if user press up and down arrow then it should get selected.
Any help on this will be helpful.
OK so i've been working on this code solid for 24 hours now and could really do with some help, I'm sure it's nothing much, but I don't have much experience with javascript.
<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%
dim objRs
dim arrPDFs
dim javascriptArrayValues
Function GetPDFsArray()
Set connString = Server.CreateObject("ADODB.Connection")
set objRS = Server.CreateObject("ADODB.Recordset")
connString.ConnectionString ="dsn=floor;uid=floor;pwd=floor;"
connString.Open
mySQL = "SELECT * FROM Companies"set objRs = connString.Execute(mySQL)
If NOT objRs.EOF OR NOT objRs.BOF Then
GetPDFsArray = objRs.GetRows()
Else
GetPDFsArray = ""
End If
End Function
'Get array
arrPDFs = GetPDFsArray
If isArray(arrPDFs) Then
for i=0 to uBound(arrPDFs,2)
javascriptArrayValues=javascriptArrayValues & """" & arrPDFs(0,i) & """" & ","
next 'i
javascriptArrayValues=Left(javascriptArrayValues,Len(javascriptArrayValues)-1)
Else
javascriptArrayValues = "Error: No results for array"
End If
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<input type="text" name="pdfDesc" id="pdfDesc" autocomplete="off" />
<script>
customarray = new Array(<%=javascriptArrayValues%>);
actb(document.getElementById("pdfDesc"),customarray);
</script>
</head>
<body>
</body></html>
As I said the page loads, but the autocomplete does nothing.
Thanks in advance to anyboby that takes the time to read this.
I'd like to be able to show the autocomplete list from within a different javascript function. Is there a function I can call?
My scenario is this: the user uses an on-screen keyboard which fires events to fill the textbox. The autocomplete works great when using an actual keyboard, but when they click the keys on the on-screen keyboard (input buttons), the list is not generated. If there is a way I can show the autocomplete list from what is already in the textbox, that would be excellent!
Well I eventually got this great bit of Javascript to pull the list of keywords from a .txt file via AJAX's XMLHttpRequest() to save hitting on the database every pageload. I plan on running a cronjob to update the file once a day from the database with the most popular keywords. Tested in IE6, IE7, Firefox 2 and Opera. The only problem I have encountered so far is the keydown, keypress etc event not working properly in Opera 9. Anyone had any success/failure in Opera with the keydown events too?
Thanks again for this great code. I am using it on a new site of my own due to go live very soon which will be a commercial site so thought I better ask if this will be okay.
Zichun, I desperately need your help! I'm working on a site using your control (easily the best one on the web, I hope you don't mind). And I'd like to call it from within a jQuery ThickBox. http://jquery.com/demo/thickbox/
The two problems I am experiencing are:
1. The auto complete renders from the "non-scrolled" location of the thickbox's text field i assigned it to. If you're scrolled down, you can't see it at all.
2. The auto complete control renders behind both the thickbox and the transparent gray that darkens the page.
I tried messing with z-index stuff, but I couldn't figure it out.
I have to use the thickbox, and I love your auto complete so much that I can't use a different one. Any help or guidance you can give me would be good. My email is henderson.mark@gmail.com, please contact me ASAP!