-4

I need add some html content to my page. I can do it like this:

$("#followUser").html('<label id="followUser"><button class="btn btn-primary" id="followUserButton"><i class="fa fa-check"></i> Unfollow</button></label>');

But I need to change button text dynamically like

$("#followUser").html('<label id="followUser"><button class="btn btn-primary" id="followUserButton"><i class="fa fa-check"></i> <?=$lng['2buttonFollow'];?></button></label>');

Second one is my solution but it does not work. Any idea? How to add some php variable by jquery?

Edit after the problem solved: It's about echo part. When I try to use short way of echo it makes fail for javascript. Actually my solution was true, just changed to echo.

Mehmet
  • 3,301
  • 8
  • 26
  • 36
  • 1
    You would have to `echo` the PHP out at the time you deliver the page. – Jay Blanchard Jul 16 '15 at 20:10
  • 1
    Does this `=` not equal to ` – Shehary Jul 16 '15 at 20:15
  • 1
    What doesn't work about it? Do you get an error? What does the generated HTML look like? Are you putting PHP code in a JavaScript file or JavaScript in a PHP file? – showdev Jul 16 '15 at 20:15
  • @showdev, i think actually he is trying to change the button text`unfollow` to `follow` dynmically and using PHP for it. – Shehary Jul 16 '15 at 20:19
  • See: [Are PHP short tags acceptable to use?](http://stackoverflow.com/questions/200640/are-php-short-tags-acceptable-to-use) – showdev Jul 16 '15 at 20:24
  • 1
    @Mehmet, would you explain _in the question_ what the difference between these two things? It seems you're making the reader do more work than they should have to do, just to understand the post. – halfer Jul 16 '15 at 20:24
  • I've updated my questions. – Mehmet Jul 16 '15 at 20:31

1 Answers1

-1

You're just passing the php variable $lng['2buttonFollow']; inside the php tags. Use echo to display the value of the variable.

$("#followUser").html('<label id="followUser"><button class="btn btn-primary" id="followUserButton"><i class="fa fa-check"></i> <?php echo $lng['2buttonFollow'];?></button></label>');
Keerthi
  • 923
  • 6
  • 22