Autocomplete sample using Jquery and CXP
Posted: Thu Jun 11, 2015 9:35 pm
http://donnay-software.com/ds/autocomplete.htm
This little app uses the Jquery Widget: AutoComplete
When you click on the above URL it will load the following in your web browser:
When you start typing in the "Choose a Performer" box it will call autocomplete.cxp and pass it the value in the input box.
autocomplete.cxp returns a JSon array with only the performers that match the value in the input box. The data could easily come from a database rather than an array.
This little app uses the Jquery Widget: AutoComplete
When you click on the above URL it will load the following in your web browser:
Code: Select all
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>autocomplete demo</title>
<link rel="stylesheet" href="./Jquery/jquery-ui-1.11.4.custom/jquery-ui.css">
<script src="./Jquery/jquery-ui-1.11.4.custom/external/jquery/jquery.js"></script>
<script src="./Jquery/jquery-ui-1.11.4.custom/jquery-ui.js"></script>
</head>
<body>
<label for="autocomplete">Choose a Performer: </label>
<input id="autocomplete">
<script>
$( "#autocomplete" ).autocomplete({
source: "./autocomplete.cxp"
});
</script>
</body>
</html>
autocomplete.cxp returns a JSon array with only the performers that match the value in the input box. The data could easily come from a database rather than an array.
Code: Select all
<!--
/// <summary>
/// Returning a JSON data stream
/// </summary>
-->
<%
cTerm := Upper(Pvalue(1))
aNames := { ;
'Annie Hall', ;
'Arlo Guthrie', ;
'Bette Midler', ;
'Bob Dylan', ;
'Bobbie Gentry', ;
'Buddy Holly', ;
'Canned Heat', ;
'Carol Elliot', ;
'Carole King', ;
'Caroline Aikin', ;
'Cat Stevens', ;
'Catie Curtis', ;
'Cheryl Wheeler', ;
'Chuck Prophet', ;
'Chuck Pyle', ;
'Crosby, Stills, Nash', ;
'Danny Kaye', ;
'Dar Williams', ;
'Dr Hook', ;
'Eliza Gilkyson', ;
'Elton John', ;
'Elvis Presley', ;
'Freddie Mercury', ;
'Gail Davies', ;
'Glenn Miller', ;
'Gordon Rowland', ;
'Greg Brown', ;
'Harry McClintock', ;
'Itzhak Perlman', ;
'James Taylor', ;
'Jan Stanfield', ;
'Jefferson Airplane', ;
'Jim Croce', ;
'Jimi Hendrix', ;
'Jimmy Dean', ;
'John Denver', ;
'Joni Mitchell', ;
'Journey', ;
'Kevin Welch', ;
'Krystian Zimermann', ;
'Led Zeppelin', ;
'Lyle Lovett', ;
'Lynn Miles', ;
'Madeleine Peyroux', ;
'Michael Jackson', ;
'Michael Lille', ;
'Mumbo Gumbo', ;
'Norah Jones', ;
'Ray Charles', ;
'Richard Pryor', ;
'Richard Shindell', ;
'Richie Havens', ;
'Robin Williams', ;
'Roy Orbison', ;
'Sam Cooke', ;
'Slobberbone', ;
'Steppenwolf', ;
'Susan Werner', ;
'Ten Years After', ;
'The Beatles', ;
'The Doors', ;
'The Eagles', ;
'The Flatlanders', ;
'The Moody Blues', ;
'Tim Bays', ;
'Toby Keith', ;
'Tom Paxton', ;
'Tom Petty', ;
'Tom Prasada-Rao', ;
'Van Morrison', ;
'Vance Gilbert', ;
'Vic Chestnutt', ;
'Willie Nelson', ;
'Yo-yo Ma', ;
'Yundi Li'}
aNames2 := {}
FOR i := 1 TO Len(aNames)
IF Left(Upper(aNames[i]),Len(cTerm)) == cTerm
AAdd(aNames2,aNames[i])
ENDIF
NEXT
cData := Var2Json( aNames2 )
::HttpResponse:ContentType := "text/json;charset=iso-8859-1"
OutputDebugStringA( Var2Char(cData ) )
::HttpResponse:Reset()
::HttpResponse:Write( cData )
%>