In a website cms I am using jquery autocomplete. I worked like a charm. But suddenly, after a few weeks, it stopped working. Absolutely no code was changed in this period. I'm using jquery 1.6.2 and jquery ui 1.8.13. Here's the code:
$(function() {
var artists = [<?php getArtists(); ?>];
$("#artistsearch").autocomplete({
source: artists,
select: function(event, ui){
$("#artistsearch").val(ui.item.artistsearch);
},
change: function(event, ui) { $("#search").submit(); }
});
});
The array artists
is a correct array, but too long to post here. I hope that there is anyone over here that can help me out on this one.
Thanks in advance, Richard
I've got a form with a field artistsearch
Edit: Thanks people..
I didn't receive notification mails, so a little late with my response.
The echo is IN the getArtist() function and delivers a nice array. As I stated in my original question the whole thing DID work, but suddenly stopped working, without changing any code. At first I thought that it could be an invalid item in the array, so I hardcoded a simple, 2 items array, and it also didn't work.
Could it be a server issue? I realy am confused with this and I didn't see this behavior in my careere before.
Problem solved!
It turned out that some of the array-items where breaking the array. In the getArtist function I switched the quotes, e.g.: "'" to '"'
Richard
Needs to be the following (assuming that your getArtists()
function doesn't already echo
), whenever you're using PHP variables inside JavaScript/JQuery you have to echo them :) OR you can use short tag (thanks diEcho):
$(function() {
var artists = [<?php echo getArtists(); ?>];
$("#artistsearch").autocomplete({
source: artists,
select: function(event, ui){
$("#artistsearch").val(ui.item.artistsearch);
},
change: function(event, ui) { $("#search").submit(); }
});
});