From 8ab3e9ed14dc643d1f0192a67655b0691e083968 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Tue, 23 Aug 2005 01:18:28 +0000 Subject: First Step in Fixing AutoComplete and Cleaning Up Code --- usr/local/www/javascript/suggestions.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 usr/local/www/javascript/suggestions.js (limited to 'usr/local/www/javascript/suggestions.js') diff --git a/usr/local/www/javascript/suggestions.js b/usr/local/www/javascript/suggestions.js new file mode 100644 index 0000000..1b30fff --- /dev/null +++ b/usr/local/www/javascript/suggestions.js @@ -0,0 +1,33 @@ + +/** + * Provides suggestions for state names (USA). + * @class + * @scope public + */ +function StateSuggestions(text) { + this.states = text; +} + +/** + * Request suggestions for the given autosuggest control. + * @scope protected + * @param oAutoSuggestControl The autosuggest control to provide suggestions for. + */ +StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/, + bTypeAhead /*:boolean*/) { + var aSuggestions = []; + var sTextboxValue = oAutoSuggestControl.textbox.value; + + if (sTextboxValue.length > 0){ + + //search for matching states + for (var i=0; i < this.states.length; i++) { + if (this.states[i].indexOf(sTextboxValue) == 0) { + aSuggestions.push(this.states[i]); + } + } + } + + //provide suggestions to the control + oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead); +}; \ No newline at end of file -- cgit v1.1