JS how right replace `&quot` on quotes

user2881809 picture user2881809 · Aug 22, 2014 · Viewed 45.5k times · Source
<input type="text" autocomplete="off" class="Autocomlete1" name="test">

$('.Autocomlete1').typeahead({
            ajax: {
                    url: './test.php?log=test',
                    triggerLength: 1
                  },
            updater: function(item) {
                    return item;
                },
            onSelect: function(item) {

                    return item;
                }
    });

After autocomplate in input we get nextvalue - Text &quot; TextTextText &quot; (database row have it value) but need output Text " TextTextText "

For replace &quot; on " i want make:

onSelect: function(item) {
  var text = item.text;
  var text = text.replace(/&quot;/g, '"');
  $('.Autocomlete1').val(text);
  return item;
}

But this is not working...

Tell me please how right replace &quot on quotes ?

Answer

Leo Loki picture Leo Loki · Aug 22, 2014

if not working var text = text.replace(/&quot;/g, '\\"'); check other lines becouse it worked for me.