Hi everyone, I am new at programming and I cannot figure out how to
get the Autocomplete's keyboard functionality to work correctly. I am
able to get Autocomplete function but when you hit the up and down
arrow, the select does not change. Could someone take a look at my
code and point out what I am doing wrong? I am using the latest stable
version of script.aculo.us.
FILE: autocomplete.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Autocomplete demonstration</title>
<script type="text/javascript" src="javascripts/prototype.js"></
script>
<script type="text/javascript" src="javascripts/effects.js"></script>
<script type="text/javascript" src="javascripts/controls.js"></
script>
<style>
body {font-family: verdana; arial, sans-serif; font-size: 12px; }
#search, ul { padding: 3px; width: 150px; border: 1px solid #999;
font-family: verdana; arial, sans-serif; font-size: 12px;}
ul { list-style-type: none; font-family: verdana; arial, sans-serif;
font-size: 12px; margin: 5px 0 0 0}
li { margin: 0 0 5px 0; cursor: default; color: red;}
li:hover { background: #ffc; }
</style>
</head>
<body>
<h2>Autocompletion example</h2>
<p>
The database searches a few of my favourite musicians - the best place
to start is by typing "the";
</p>
<div>
<label>Type here</label> <input type="text" id="search"
name="search" />
</div>
<div id="hint"></div>
<script type="text/javascript">
new Ajax.Autocompleter("search","hint","livesearch2.php");
</script>
</body>
</html>
------------------------------------------
FILE: livesearch2.php
<?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("artists.xml");
$x=$xmlDoc->getElementsByTagName('music');
date_default_timezone_set('America/Chicago');
//get the q parameter from URL
$q=$_POST['search'];
//lookup all links from the xml file if length of q>0
$j=0;
if (strlen($q)>0)
{
echo("<ul>");
for($i=0; $i<($x->length); $i++)
{
$music = $x->item($i);
$music_id =
$music->getElementsByTagName('title')->item(0);
$y=$x->item($i)->getElementsByTagName('id');
$z=$x->item($i)->getElementsByTagName('title');
if ($z->item(0)->nodeType==1)
{
//find a link matching the search text
if
(stristr($z->item(0)->childNodes->item(0)->nodeValue,$q))
{
echo("\t<li id=\"" . $j++ . "\" >");
echo($music_id->nodeValue);
echo("\t</li>");
}
}
}
echo("</ul>");
}
?>
------------------------------------
FILE: artists.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<art>
<music>
<id> 4 </id>
<title>The Clash</title>
</music>
<music>
<id> 5 </id>
<title>Animal Collective</title>
</music>
<music ID="6">
<id> 6 </id>
<title>MGMT</title>
</music>
<music>
<id> 7 </id>
<title>The Dead Kennedys</title>
</music>
<music>
<id> 8 </id>
<title>Bad Religon</title>
</music>
<music>
<id> 9 </id>
<title>Minor Threat</title>
</music>
</art>
I have tried the same approach except using a SQL server instead of
searching an XML file and I get the same results. Any help or tips
would be greatly appreciated.
--
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en.