0

I have a problem with single quote ('):

<button type="button" class="tasto btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" 
                        onclick="myFunction('[blkfeatured.lastname]')">

If lastname = "Mario Rossi", this works, but
If lastname = "Stefano d'Orazio", it doesn't work, because I've created another ', and then
I have syntax error.

Look this example (please copy and try it):

<button type="button" onclick="nominativo = 'Mario Rossi'; myFunction(nominativo)">
    <span>Vedi informazioni</span>
</button>

<script type='text/javascript'>
    function myFunction(nominativo) {
        alert(nominativo);
        iframe.src = 'nomesito.php?nome=' + nominativo;
    }
</script>   

Now... if you try this program WORK, but if you change lastname: "nominativo = 'Stefano d'Orazio' don't work.

Can you help me?

  • 1
    Ever heard of Escape Chars ? – dipak_pusti Dec 30 '17 at 02:09
  • 1
    Possible duplicate of [Javascript - How to show escape characters in a string?](https://stackoverflow.com/questions/21672334/javascript-how-to-show-escape-characters-in-a-string) – SherylHohman Dec 30 '17 at 07:28
  • Look here for characters that need escaping in Javascript https://stackoverflow.com/a/21672439/5411817 And here to see an example regex that you may modify for your needs: https://stackoverflow.com/a/17552048/5411817 – SherylHohman Dec 30 '17 at 07:33

1 Answers1

0

In a TBS tag, use parameter strconv=js in order to escape a Javascript string.

<button ... onclick="myFunction('[blkfeatured.lastname;strconv=js]')" />

For more details, see the doc

Skrol29
  • 5,402
  • 1
  • 20
  • 25