PDA

View Full Version : Suggestion for database


FlashO
04-23-2008, 03:18 PM
Hi กกกกก
I am using this code for an auto-complete of a text box. Rather than take that Cities of the code, I want to take the Cities of a table in my database.
Is that possible?
Thanks :)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0058)http://www.pengoworks.com/workshop/jquery/autocomplete.htm -->
<HTML><HEAD><TITLE>jQuery Autocomplete</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<SCRIPT src="jQuery%20Autocomplete_archivos/jquery.js"
type=text/javascript></SCRIPT>

<SCRIPT src="jQuery%20Autocomplete_archivos/jquery.autocomplete.js"
type=text/javascript></SCRIPT>
<LINK href="jQuery%20Autocomplete_archivos/jquery.autocomplete.css"
type=text/css rel=stylesheet>
<META content="MSHTML 6.00.5730.13" name=GENERATOR></HEAD>
<BODY>
<H1>&nbsp;</H1>
<FORM onSubmit="return false;" action="">
<P>Nuevo Tag: <INPUT id=CityLocal> <INPUT onclick=lookupLocal(); type=button value=">">
</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
</FORM>
<SCRIPT type=text/javascript>
function findValue(li) {
if( li == null ) return alert("No match!");

// if coming from an AJAX call, let's use the CityId as the value
if( !!li.extra ) var sValue = li.extra[0];

// otherwise, let's just display the value in the text box
else var sValue = li.selectValue;

alert("The value you selected was: " + sValue);
}

function selectItem(li) {
findValue(li);
}

function formatItem(row) {
return row[0] + " (id: " + row[1] + ")";
}

function lookupAjax(){
var oSuggest = $("#CityAjax")[0].autocompleter;

oSuggest.findValue();

return false;
}

function lookupLocal(){
var oSuggest = $("#CityLocal")[0].autocompleter;

oSuggest.findValue();

return false;
}

$(document).ready(function() {
$("#CityAjax").autocomplete(
"autocomplete_ajax.cfm",
{
delay:10,
minChars:2,
matchSubset:1,
matchContains:1,
cacheLength:10,
onItemSelect:selectItem,
onFindValue:findValue,
formatItem:formatItem,
autoFill:true
}
);

$("#CityLocal").autocompleteArray(
[
"Aberdeen", "Ada", "Adamsville", "Addyston", "Adelphi", "Adena", "Adrian", "Akron",
"Albany", "Alexandria", "Alger", "Alledonia", "Alliance", "Alpha", "Alvada",
"Alvordton", "Amanda", "Amelia", "Amesville", "Amherst", "Amlin", "Amsden",
"Amsterdam", "Andover", "Anna", "Ansonia", "Antwerp", "Apple Creek", "Arcadia",
"Arcanum", "Archbold", "Arlington", "Ashland", "Ashley", "Ashtabula", "Ashville",
"Athens", "Attica", "Atwater", "Augusta", "Aurora", "Austinburg", "Ava", "Avon",
"Avon Lake", "Bainbridge", "Bakersville", "Baltic", "Baltimore", "Bannock",
"Barberton", "Barlow", "Barnesville", "Bartlett", "Barton", "Bascom", "Batavia",
"Bath", "Bay Village", "Beach City", "Beachwood", "Beallsville", "Beaver",
"Beaverdam", "Bedford", "Bellaire", "Bellbrook", "Belle Center", "Belle Valley",
"Bellefontaine", "Bellevue", "Bellville", "Belmont", "Belmore", "Beloit", "Belpre",
"Benton Ridge", "Bentonville", "Berea", "Bergholz", "Berkey", "Berlin",
"Berlin Center", "Berlin Heights", "Bethel", "Bethesda", "Bettsville", "Beverly",
"Bidwell", "Big Prairie", "Birmingham", "Blacklick", "Bladensburg", "Blaine",
"Blakeslee", "Blanchester", "Blissfield", "Bloomdale", "Bloomingburg",
"Bloomingdale", "Bloomville", "Blue Creek", "Blue Rock", "Bluffton",
"Bolivar", "Botkins", "Bourneville", "Bowerston", "Bowersville",
"Bowling Green", "Bradford", "Bradner", "Brady Lake", "Brecksville",
"Bremen"
],
{
delay:10,
minChars:1,
matchSubset:1,
onItemSelect:selectItem,
onFindValue:findValue,
autoFill:true,
maxItemsToShow:10
}
);
});
</SCRIPT>

<BLOCKQUOTE>
<H3>&nbsp;</H3>
</BLOCKQUOTE>
</BODY></HTML>

A1ien51
04-24-2008, 07:08 PM
I would suggest that you look into one of the Ajax libraries that has the control such as YUI http://www.yahooapis.com/yui/autocomplete/

Eric