1

I have the following JavaScript:

 $( "#calculatorFromId" ).autocomplete({
                 source: function( request, response ) {
                     $.ajax({
                         url: "${autosuggestCurrenciesUrl}",
                         dataType: "json",
                         data: {
                             term: request.term
                         },
                         success: function( data ) {
                                response(data);

                         }
                     });
                 },
                minLength: 2,
                delay: 0,
focus: function(event, ui) {

$( "#calculatorFromId").
val(ui.item.label.replace('ä','ä').replace('ü','ü').
replace('ö','ö').replace('Ä','Ä').replace('Ü','Ü').#
replace('Ö','Ö') + "(" + ui.item.id +")");
return false;
}    

The German Umlaut is not correctly displayed. Do you know what value should I pass for the second argument in the replace function ? Every value I pass, it is displayed in the textfield exactly how it was passed. No conversion is done.

Thank you!

  • 1
    Isn't the second argument right? What is the value of `ui.item.label`? Maybe you can `console.log` the original, and after replacing, and post it here. – augustomen Nov 04 '13 at 10:54
  • 1
    Note that `.replace`, when given a string for the search argument, only replaces the **first** match. To do a global replace, you have to use a regular expression with the "global" flag (`g`) as the search argument, e.g.: `.replace(/\ä/g, 'ä')`. – T.J. Crowder Nov 04 '13 at 10:54
  • I mean, "ä" is displayed as "ä" in the text field. The match is correctly done. The problem is about the way the Umlaut ä, in order to be correctly displayed – Alexandru Jecan Nov 04 '13 at 11:02
  • 4
    _“I mean, "ä" is displayed as "ä" in the text field”_ – that means you have a character encoding problem. – CBroe Nov 04 '13 at 11:19
  • 1
    possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – deceze Nov 04 '13 at 11:25
  • I have tried to change the charset, but it doesn't help. – Alexandru Jecan Nov 04 '13 at 13:23
  • Then you have not done it properly … you really _should_ be using UTF-8, everything else does not make sense for current web applications/web sites. – CBroe Apr 27 '14 at 23:57

2 Answers2

0

The response text must be urlencoded and your local javascript must decode this encoded text with unescape(). So you can bypass german umlaute.

0

To add text with German special characters via JavaScript you could use String.fromCharCode(220) (=Ü) To find the code for a character use http://unicode-table.com/ example: var text = String.fromCharCode(220) + "berschrift" (=Überschrift)

Anja
  • 473
  • 4
  • 12