Insert a carriage return in a JavaScript string

Y

yellowtek

Hi,

I've got some JavaScript inserted within a PHP echo instruction:
<?php>
echo " ... javascript ...."
<?>

This context may be important, I don't know...


At some point within the JavaScript, I want to add a carriage return at
the end of a field value:
str = str + '\n';

but this writting does not work, because the Javascript produced in the
html page gives:
str = str + '
'
How to do this?

Thanks.

Herve.
 
M

McKirahan

yellowtek said:
Hi,

I've got some JavaScript inserted within a PHP echo instruction:
<?php>
echo " ... javascript ...."
<?>

This context may be important, I don't know...


At some point within the JavaScript, I want to add a carriage return at
the end of a field value:
str = str + '\n';

but this writting does not work, because the Javascript produced in the
html page gives:
str = str + '
'
How to do this?

FYI:
str +' "\n"
is the same as
str = str + '\n';

Depending on your usage you may have to "escape"
the backslash; for example \\n.

However, "<br>" may be applicable instead.

What causes the "Javascript produced in the html page"?

Show us your code...
 
Y

yellowtek

The javascript "produced" is what you get in the browser as a source
code when the PHP page is executed, that is:
echo "... javascript.....";

And the reason of the insertion of JavaScript within this PHP echo is
the share of PHP constants:
<?php>
include ("inc/constants.inc.php");
echo "
str = str + '".A_CONSTANT."';
";
<?>

I will try the double \; that might be the solution.
Thanks.

McKirahan a écrit :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top