Mixing javascript, jQuery and PHP, newline -
ok, have few things here:
javascript:
desc = "line 1 \n line 2" jquery:
$("#msg").text(desc); php:
const num = 555; what want, change text of <p> id of msg, contain piece of text number of lines, , in 1 of them number php constant.
like so:
line 1
 line 2 555, line 2 continued 
 line 3
my problem how mix them all? tried following:
var desc = "line 1 \n line2" + <?php echo num ?> +"\n line 3"; , doesn't work.
there several issues code:
- php constants should defined using define("constant_name", "value");syntax;
- \nhas no effect inside html tag (if dont apply- white-space: pre;or- pre-wrap);
- <?php echo num; ?>should wrapped- "or should inside javascript string;
- $("#msg").text(desc)remove tags- desc, need use- .html(desc)instead.
what need this:
php
define("num", 555); javascript
var desc = "line 1<br/>line2 <?php echo num; ?><br/>line 3"; $("#msg").html(desc); 
Comments
Post a Comment