HTML call for euro symbol not interpreted in textarea?

Shows €instead of the sign € (currency) in the text box. Does anyone have an idea why this is going wrong?

<?php
$currency = "&euro;"; //using php with other data from database

echo "<script>
      $('#share_button').click(function(e){
      // pass the currency to javascript and put in textarea shared with other on clicks
           $('#snsdescp').val(`".$currency."`);
      });</script>";
?>

 //shared textarea
<textarea class="form-control" name="message" id="snsdescp"></textarea> 
+4
source share
4 answers

The method val()does not encode / decode, as a hack you can use the function html()to encode, and then fade the text:

$('#share_button').click(function(e){
    $('#snsdescp').val($("<div>").html("&euro;").text());
});

Here is a working jsFiddle for your text box.

+3
source

You can set it by assigning an element &euro;property :innerHTMLtextarea

document.querySelector('#snsdescp').innerHTML = '&euro;';

If you want to use jQuery, you can simply call its method .html():

$('#snsdescp').html('&euro;');
0

, , php, , , javascript. .

<?php
  $currency = "\u20ac"; //using php with other data from database
?>

 <textarea class="form-control" name="message" id="snsdescp"></textarea> 
  <br/><br/>
  <div id="share_button" >hello</div>//suppose your id is here

 <script>
    var value ="<?php echo $currency;?>"; //store php value in js variable
    $("#share_button").click(function(){

        $("#snsdescp").val(value);

     });
  </script>
0
source

You can use Unicode for € \ u20AC

$('#snsdescp').val("\u20AC");

0
source

Source: https://habr.com/ru/post/1661783/


All Articles