views:

16

answers:

1

Using an ajax autosuggest script that queries a mysql database as I enter names. As I type in a name with an accent, the dropdown shows different characters than the ones I've typed in. For example as I type in the last name Hylén, the Ajax dropdown shows Hylén. This occurs if the name is not in the database.

$(document).ready(function(){

$("input[id^='last_']").autocomplete('suggest.php',{

matchCase:true,

formatItem: function(data, i, total)

{

var s=data[0].split(",")

return s.join(" "); 

}

});


$("input[id^='last_']").result(function(event, data, formatted){

var ids=this.id.split('_')

var id=ids[1]; // from last_xx got xxx

var s=html_entity_decode(data[0]).split(","); // first,middle,last

$(this).next().focus();

$(this).next().select();

//have only last value -- TAB pressed

if(s.length==1)return;

$('#first_'+id).val(s[0]);

$('#middle_'+id).val(s[1]);

$('#last_'+id).val(s[2]);

});

});

What should I be looking at to fix this?

+2  A: 

I think you should look at your encoding. Looks like "é" is the 2 Unicode bytes of "é" printed as ANSI or whatever. Make sure that you use UTF8 (or UTF16 or whatever charset can handle all your characters) consistently in

  • the database
  • all code files (PHP, Javascript etc)
  • HTTP headers
  • HTML headers

Hope that helps!

Philipp
specifically, "é" is `\xc3\xa9` which is `é` in UTF-8
cobbal
Thanks...I'll have to make sure I convert to UTF-8.
Ian