Quotation inside quotation marks to send string parameter

4

The PHP line of code below should be displayed on the website and called using JavaScript.

        echo "
        <div class='tipoPagamento' onclick='SelecionarTipoPagamento({$row['CODIGO']}, '{$row['TIPO']}');'>
            <font color='#fff'>
                <h4 style='margin-top: -15px;'>{$row['ESPECI']}</h4>
            </font>
        </div>
    ";

In the second line, in the div tag .. I have to call the function 'SelectPayment Type (int, str)'. As I indicated, it has an integer parameter and another string .. so I put the variable $ row ['TYPE'] in quotation marks. But the function is not being called because it is in error.

Removing the string parameter works fine and the code looks like this:

            echo "
        <div class='tipoPagamento' onclick='SelecionarTipoPagamento({$row['CODIGO']});'>
            <font color='#fff'>
                <h4 style='margin-top: -15px;'>{$row['ESPECI']}</h4>
            </font>
        </div>
    ";

I think I'm not sure how to use the quotes correctly, but from what I saw on the internet it's correct ... what would be the mistake?

I'm using the following scripts: (I'm specifying because I've heard that some do not accept single quotes or something)

<script src="js/jquery.min.js"></script>
    <script src="js/database.js"></script>
    <script src="js/jquery.poptrox.min.js"></script>
    <script src="js/jquery.scrolly.min.js"></script>
    <script src="js/jquery.scrollex.min.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script src="js/skel.min.js"></script>
    <script src="js/init.js"></script>
    <script src="js/jquery.mask.js"></script>
    <noscript>
        <link rel="stylesheet" href="css/skel.css" />
        <link rel="stylesheet" href="css/style.css" />
        <link rel="stylesheet" href="css/style-wide.css" />
        <link rel="stylesheet" href="css/style-normal.css" />
    </noscript>
    <script src="js/jquery-1.11.2.min.js"></script>
    <script src="js/jquery.maskedinput.min.js"></script>

The 'SelectPayment ()' function is this:

function SelecionarTipoPagamento(cod, tipo){
alert("oi");
alert(cod);
alert(tipo);
codTipoPagamento = cod;}
    
asked by anonymous 11.06.2015 / 19:42

2 answers

4

onclick='funcao('str');'

echo "
        <div class='tipoPagamento' onclick=\"SelecionarTipoPagamento({$row['CODIGO']}, '{$row['TIPO']}');\">
            <font color='#fff'>
                <h4 style='margin-top: -15px;'>{$row['ESPECI']}</h4>
            </font>
        </div>
    ";
    
12.06.2015 / 05:16
1

Close the quotation marks in the function and then reopen. Really, this may be the error.

echo "<div class='tipoPagamento' onclick='".SelecionarTipoPagamento($row['CODIGO'])."'>
            <font color='#fff'>
                <h4 style='margin-top: -15px;'>{$row['ESPECI']}</h4>
            </font>
        </div>
    ";
    
11.06.2015 / 19:46