user2881809
user2881809

Reputation:

JS how right replace `&quot` on quotes

<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 ?

Upvotes: 9

Views: 65084

Answers (2)

Leo Loki
Leo Loki

Reputation: 2585

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

Upvotes: 32

Shivang MIttal
Shivang MIttal

Reputation: 1001

" is also needs a escape character before in string write '\"

 var text = text.replace(/&quot;/g, '\\"');

Upvotes: 7

Related Questions