-1

I have this like-sample

<div class="canvas_container">
    <div id="messages_box" class="messages_box">
        <div id="messages_label"></div>
    </div>
    
    <form id="data_form">
    ....
    </form>
</div>

and once I saved correctly data I want to show the message to the user and invite him to login :

$data_complete = "<strong>" . _e("Data are updated. Goto at login page ","xxxxxxxx") . "<a href='" . wp_login_url() . "'></a></strong>";
?>
    <script type="text/javascript">
        $(document).ready(function(){
            $("#messages_label").text(("<?= $data_complete; ?>").html());
            $("#messages_box").show();
            $("#data_form").reset();
        });
    </script>
<?php

but the message doesn't show inside messages_box... initial part goes under ::before of one of main div nodes, plus in Console I see this error:

Uncaught SyntaxError: missing ) after argument list

what I did wrong?....

Thanks to all in advance! Cheers!

Edit: solved!.... it was properly that _e() thing because it translate and echo/output the string passed to it. So I had to use __() to return just the translated string. Cheers!

Luigino
  • 545
  • 2
  • 5
  • 21
  • 1
    What you're doing is susceptible to all sorts of problems with `"` and such in the text. Instead, encode it properly as shown in the linked question's answers. Also, separately, you have what looks like a typo: `$("#messages_label").text(("= $data_complete; ?>").html());` The `(...).html()` will try to call a method on the string inside the `()`, which you probably didn't mean to do. (I don't know what you did mean to do, but that looks off.) – T.J. Crowder Jan 29 '22 at 11:38
  • I was using that .html() because in the variable I put some html elements like that ... – Luigino Jan 29 '22 at 11:56
  • 1
    Strings don't have an `html` method. jQuery objects do, but again, you're calling it on the result of `("...")`, which will be a string. – T.J. Crowder Jan 29 '22 at 11:57

0 Answers0