I dont think this was mentioned, but yes you can have multiple text boxes with individual auto-complete. When you are defining the textbox and auto-complete array just add "new" before the function. Look below for an example:
var obj1 = new actb(document.getElementById('make'),arrMake);
var obj2 = new actb(document.getElementById('model'),arrModel);
var obj3 = new actb(document.getElementById('engine'),arrEngine);
my question was if the variables that define if the input text box will be limited to given options defined already is specific to input text box or it is defined per instance of actb Object
10x ahead,
BTW, is it function quickly will huge collection of options?
This is a simple thing, but is kind of neat. If you changed the mouse icon from a text (I-Beam) to a pointer. All you have to do is set the style.cursor = 'pointer' (see http://www.quirksmode.org/css/cursor.html for details).
Makes it more obvious when the user selects the entry with a mouse (also makes it a bit easier to select something).
If the autocomplete input is within a form, pressing enter will not only complete the text box, but will also submit the form. Is there any way to catch the enter keypress before it submits the form and cancel it?
I have tried this with testarea on IE 6, Firefox 1.0.4, Mozilla 1.7 and Netscape 8 and it works fine. So you just need to pass on the id od the textarea instaed of text box.
On Netscape 6, there seems to be problem with textarea although basic functionality is working fine for text boxes (except for some javascript errors).
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?
Thanks for your help.
Adam
Last Visit: 31-Dec-99 18:00 Last Update: 28-Sep-24 8:19