Use php to pass multiline text to javascript

Asked

Viewed 39 times

0

I would like to pass a text with multiple in a Javascript function that is mounted in PHP.

public function change_meta_info_icon($property)
    {
        if($property['metas'] && $property['metas']['socialdb_property_help'] && !empty(trim($property['metas']['socialdb_property_help']))){
            ?>
                <button onclick="showHelpText('<?php  echo ($property['metas']['socialdb_property_help']) ?>');" class="btn btn-default btn-xs">Ajuda</button>
            <?php
        }
        ?>
        <?php

    }

The function showHelpText should receive the text and pass it to a modal window but as the text has ' n', parentheses, quotes and everything else this generating problems.Resultado após a execução do código

  • You want to return something in php to js is that it? Why don’t you try going through json?

  • 2

    Have several ways to solve one of them is to escape your quotes from showhelptext("..., The other is to put all content in a hidden div for example is to pass the id of div as a parameter of your function ...

  • Thanks, I ended up using the hidden div with the text.

  • @Andrealvim If solved your problem. Mark as solved.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.