I would be also interested in such a function, I'm using a Google Suggest style keyword refresh (every 300 ms it reads the entered textbox value and feeds the keywords to the object - I made the actb_generate() global but it seems that it doesn't catch it properly, probably because of response delay, so I'd like a function to generate the list without the onkeydown)
I am fetching data via xmlhttp request, and I get a javascript array from a database. I would like to subsitute this array 'on-the-fly' into the autocomplete.
Is this as simple as calling the actb(this,event,customarray) function again upon each update?
What would be the syntax to call this function for the autocomplete from my data call-back function? I could replace the 'this' with document.getelementbyid('myautocomplete'). But I don't know what that 'event' field is or does. I would put my array into the 'customarray' place.
Your code rocks, it is exactly how I would like to solve a problem of having a drop down list, ugh.
I can't figure this out though, even with the new version.. I have a sql table with keywords that i want to have populate an array to show when users type.
I have the sample autocomplete.htm working, changed it to autocomplete.jsp, and have created a recordset that pulls the keywords out of a sql table.
I dont know what to do with this however, how to work it into your code. Here is what my page looks like now..
<%@ page language="java" import="java.sql.*" %>
<%@ include file="Connections/webcat.jsp" %>
<%
Driver Driverkeywords = (Driver)Class.forName(MM_webcat_DRIVER).newInstance();
Connection Connkeywords = DriverManager.getConnection(MM_webcat_STRING,MM_webcat_USERNAME,MM_webcat_PASSWORD);
PreparedStatement Statementkeywords = Connkeywords.prepareStatement("SELECT * FROM dbo.WDINterm ORDER BY term ASC");
ResultSet keywords = Statementkeywords.executeQuery();
boolean keywords_isEmpty = !keywords.next();
boolean keywords_hasData = !keywords_isEmpty;
Object keywords_data;
int keywords_numRows = 0;
%>
<html>
<head>
<script language="javascript" type="text/javascript" src="actb.js"></script>
<script language="javascript" type="text/javascript" src="common.js"></script>
<script>
var customarray=new Array('an apple','alligator','elephant','pear','kingbird','kingbolt', 'kingcraft','kingcup','kingdom','kingfisher','kingpin');
var custom2 = new Array('something','randomly','different');
</script>
</head>
This works fine, it is still pulling words from customarray. How do I get my items to show up instead? I don't want to hard code them as they will change often.
I'm not sure how to change the var obj = actb(document.getElementByID('tb'),customarray);
to include my resultset instead. How does the syntax differ when I want to use a resultset? Do I need to put the values into a different array? Can someone help me get this working?
var customarray=new Array('an apple','alligator','elephant','pear','kingbird','kingbolt', 'kingcraft','kingcup','kingdom','kingfisher','kingpin');
var custom2 = new Array('something','randomly','different');
var custom3 = new Array(<%
int count = 0;
while (keywords.next()) {
out.println("'");
out.println(keywords.getString("term"));
count=count+1;
out.println("'");
out.println(",");
}
keywords.close();
%>);
var obj = actb(document.getElementById('tb'),custom3);
//setTimeout(function(){obj.actb_keywords = custom2;},10000);
I really like your autocomplete control. It's great. I have a tweak I want to make. To make my explanation easy, let's say I have a simple array of ('banana', 'apple', 'orange', 'grape', 'mango') What I want to happen is this:
1.) the user types in 'a' and the dropdown will show all the elements in the array.
2.) But if the user types in 'a ng'. I want the autocomplete to show all elements that have an 'a' AND a 'ng'. In this example the dropdown should show 'orange' and 'mango'. How can do I this?
It's a great code. However, something is missing to be perfect . It would be great to have a feature for customization of the number of characters that start the auto-complete control, i.e after the 3rd wrote character.
Any quick easy way to get the code to work in Safari as well? Thanks! It's an awesome script! I'm using it for our free medical clinics to help ease our data entry.
Great code... works very well. However, immediately I found that I couldn't tab around forms like I'm used to doing. That is to say, when in a field that is using the functionality, I cannot tab out of it. It seems that when the tab key is pressed, we need to look at the previous character. If that character is the start of the field, a space, or a delimiter, then the tab should act normally by advancing the cursor to the next form field.
I found the need to warn users when they were attempting to enter data that was not in the drop down list. To do this I simply change the text color in the <INPUT> box when no matches are found.
INSTRUCTIONS:
In function "actb_generate()", replace lines 2-5 with the following code.
This was the quick and dirty solution. A more complete method would be to move the actual color values up into the area where the style variables are set for the drop down. ...but I figured the simple example was easiest to convey.
I am using this to sort through lists of a couple thousand items and it is MUCH better than simply asking a user to scroll through a huge <SELECT> box. ...Thanks a bunch!
This is a great piece of code! Works very quickly and reliably, even when it has to call my clunky code everytime it fills a text box!
I was wondering however, if you could tell me how to display a complete list? i.e. when the user types in a '*' or some other special character, the entire array which is passed to actb() is displayed?
I'd appreciate it if you could give me a hint on how to do that, or point to a place in your code that could help me start.
In case anyone is interested, entering a period "." into an autocomplete text box allows one to view the entire list!
This should probably be documented in the article, as I spent quite a bit of time writing additional methods to handle this functionality, only to discover it was already present!
Hi,
nice work and really fast... Thanks'
Is there a way where I can return (retrive) the index of the choosen element in my custom array...Since I am not using the entries in the array direclty?
Any idea pelase!
this code is nice.but if this code can get data from database with xml it coluld be nicer.when i key pressed any key on textbox data must be updated.How can i do this.or is it imposssible ?
thanks
mbozdag at vodasoft dot com dot tr
Last Visit: 31-Dec-99 18:00 Last Update: 28-Sep-24 8:38