autocomplete error

K

Kalvi

Hi!

I can´t find mistake of this code. No errors on page. But no results too.

<?php
$fruits=array();
$i=0;
$yhendus= mysql_connect('****','******','*****');
mysql_select_db("weuroh");
$p2ring = mysql_query("SELECT rahastaja FROM arhiiv_projektid group by
rahastaja");
while($rida = mysql_fetch_array($p2ring))
{
$fruits2[$i++]=$rida["rahastaja"];
}
?>
<script>
var fruits =new Array(<?php echo sizeof($fruits2); ?>);
<?PHP
for($i=0;$i<sizeof($fruits2);$i++) {
echo "fruits[" . $i . "]=\"" . $fruits2[$i] . "\";\n";
}
?>
function autocomplete(n,ac_array){
if (n.value == "") return 0;
if (event.keyCode == 8 && n.backspace){
n.value = n.value.substr(0,n.value.length-1);
n.backspace = false;
}

var r = n.createTextRange();
tmp= n.value;
if (tmp == "")return 0;
for (z=0;z<ac_array.length;z++){
tmp2 = ac_array[z];
count = 0;
for (i = 0;i<tmp.length;i++){
if (tmp2.charAt(i) == tmp.charAt(i)){
count++
}
}
if (count == tmp.length){
diff = tmp2.length - tmp.length;
if (diff <= 0) break;
kap = "";
for (i=0;i<tmp2.length;i++){
if (i >= tmp.length) kap += tmp2.charAt(i);
}
n.backspace = true;
r.text += kap;
r.findText(kap,diff*-2);
r.select();
return 0;
}
}
n.backspace = false;
return 0;
}

</script>

<input name='fruit' type='text' class='textbox' title="Opening"
onkeyup="autocomplete(this,fruits)" size="20">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top