Introduction
I occasionally run into situations where it would be really great to
add an feature to a text input on a web form. That is,
something along the lines of Auto Complete
Background
There are a bunch of scripts available on the Internets to handle this
for you, but they all do things their own way, and they're never
exactly what yor want. I'm always running into the same problems with
them
So, I finally broke down and wrote my own script. It may not be
better than what's out there, but hopefully it's easier to understand.
- The usual situation is that I want
to customize some element of the script's behavior, but the code is so
dense and obtuse that I can't make changes without breaking things.
- No documentation. A big hairy mass of code is even harder to deal with if you don't know what it's supposed to do in the first place.
It seems to work pretty well for me, so I've given it a super-snazzy
name, and wrapped it up with some doc in a zip file for you guys. Just
to make it official
Using the code
just put this javascript an add one line in you page like this
<script type="text/javascript">
window.onload = function () {
var oTextbox = new AutoSuggestControl(document.getElementById("txt1"), new StateSuggestions());
}
</script>
matches criteria are set
currently it is not set.but you can set it here
StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl ,
bTypeAhead )
{
var aSuggestions = [];
var sTextboxValue = oAutoSuggestControl.textbox.value;
if (sTextboxValue.length > 0)
{
for (var i=0; i < this.states.length; i++)
{
if (this.states[i].toLowerCase().indexOf(sTextboxValue.toLowerCase()) == 0)
{
aSuggestions.push(this.states[i]);
}
}
}
oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
};
in the for loop you can set your criteria it may be uppercase or lowercase
Points of Interest
if you are using html controlthen no prblem but you are using dotnet textbox control so
<asp:TextBox runat="server" ID="txt_City" AutoCompleteType="Disabled"></asp:TextBox>